standard input to commands in a shell script
Don Libes
libes at cme.nist.gov
Sat Oct 13 02:37:37 AEST 1990
In article <1990Oct12.025833.13376 at cubmol.bio.columbia.edu> ping at cubmol.bio.columbia.edu (Shiping Zhang) writes:
>When I invoke the following script, the process always pauses at
>the password prompt. I have to hit the return key to make it
>proceed. I don't know what's the problem. I appreciate
>it if anyone can point out the problem for me.
>ftp genbank.bio.net << END
>ftp
>ident
>ls
>quit
>END
The problem is that ftp (as do most programs) reads passwords from
/dev/tty, ignoring your i/o redirection. There is no shell mechanism
to get around this. An easy and general approach is to use expect.
Here's an expect script that will do what you want.
spawn ftp genbank.bio.net
expect "*Name*:*"
send "ftp\r"
expect "*Password:"
send "ident\r"
expect "*failed*ftp>*" exit \
"*logged*in*ftp>*"
send "ls\r"
expect "*ftp>*"
send "quit\r"
Don Libes libes at cme.nist.gov ...!uunet!cme-durer!libes
More information about the Comp.unix.shell
mailing list