expect script doesn't understand '$1' from command line?

expect script doesn't understand '$1' from command line?

Post by oa » Mon, 12 Jul 1999 04:00:00



I have the following expect script to automate a simple ftp transfer
but it doesn't take the '$1' from the command line for some reason.
Anyone know how I could get it to do that?

--------------------------------------------------
#!/usr/bin/expect
#
#
#set prompt "(%|#|\\$) $"                ;# default prompt
#catch {set prompt $env(EXPECT_PROMPT)}

eval spawn ftp ftp.eskimo.com
interact -o -nobuffer -re ftp.iglou.com:root return
send "oak\r"
interact -o -nobuffer -re assword: return
send "mypassword\r"
interact -o -nobuffer -re ftp> return
send "put"
send $1\r"
interact -o -nobuffer -re ftp> return
send "bye\r"
#interact -o -nobuffer -re $prompt return
interact
--------------------------------------------------

All I get is the follow error:

     ftp>can't read "1": no such variable
         while executing
     "send $1..."

Thanks,

-Tony

 
 
 

expect script doesn't understand '$1' from command line?

Post by Kenny McCorma » Mon, 12 Jul 1999 04:00:00



>I have the following expect script to automate a simple ftp transfer
>but it doesn't take the '$1' from the command line for some reason.
>Anyone know how I could get it to do that?

Well, for openers, you should be using the 'expect' command below, not
'interact'.  It looks like you are using a lot of options and flags to get
interact to do what expect was originally designed to do.  Also, you used
"eval spawn ftp ..." - lose the eval, it is unnnecessary.

Second, in order to access the command line args in Expect (I.e., in tcl),
you have to manipulate the argv variable using the list commands.  I usually
use 'lindex' thusly: set arg1 [lindex $argv 0]

Alternatively, you might want to wrap the thing up as a /bin/sh script
instead of as an Expect script. Then you can do something like:

#!/bin/sh
expect -c 'spawn ftp foo.bar
expect >
send "'$1'\r"
....
'

 
 
 

1. kill -9 `ps -u`whoami` | grep $1 | awk '{print $1}'`

Hi,

Could you help me debugging a simple csh script:
This script is intended to kill a process by just giving its name, e.g.
KILL this_process

I do it like this:

kill -9 `ps -u`whoami` | grep $1 | awk '{print $1}'`

and actually it tries to kill everything (including my term of course)

The following line works fine:

ps -u`whoami` | grep this_process | awk '{print $1}'

and gives the proper PID

If you have a more elaborated script for that It could be a nice training
example for me.

Thanks for any help.

2. How to spoon the newsgroups from outside our intranet?

3. 'su --login user -c command' doesn't run loggin scripts

4. Problem with Java Servlet

5. Can't get '$1' to work in a .profile alias

6. Weird system crashes...

7. Why doesn't sed 's/$/^M/' work as expected?

8. OS transfer from Slice 2 to Slice 3

9. doesn't sendmail understand 'm' flag ?

10. How 'source' a Bourne script from a tcsh command line ?

11. alias RM='mv $1 ~/garbage/'

12. How expand the variable inside '$1'?

13. Q: alias psef='ps -ef $1'