[comp.unix.shell] standard input to commands in a shell script

ping@cubmol.bio.columbia.edu (Shiping Zhang) (10/12/90)

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. Do you have the same
problem if you try it? I'm working on a Sun-3 with os4.1. I appreciate
it if anyone can point out the problem for me. Thanks.

# cut here 
ftp genbank.bio.net << END
ftp
ident
ls
quit
END

libes@cme.nist.gov (Don Libes) (10/12/90)

In article <1990Oct12.025833.13376@cubmol.bio.columbia.edu> ping@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@cme.nist.gov      ...!uunet!cme-durer!libes

barnett@grymoire.crd.ge.com (Bruce Barnett) (10/13/90)

>   In article <1990Oct12.025833.13376@cubmol.bio.columbia.edu> ping@cubmol.bio.columbia.edu (Shiping Zhang) writes:

>>ftp genbank.bio.net << END
>>ftp
>>ident
>>ls
>>quit
>>END

In article <7219@muffin.cme.nist.gov> libes@cme.nist.gov (Don Libes) writes:

>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. 

News to me. I have always done this, which works fine.

set HOST=`hostname`
set SOURCE=machine.edu
set temp=/tmp/file
ftp -n $SOURCE <<END
user anonymous $HOST
get pub/file $temp
quit
END
--
Bruce G. Barnett	barnett@crd.ge.com	uunet!crdgw1!barnett

meissner@osf.org (Michael Meissner) (10/13/90)

In article <BARNETT.90Oct12133123@grymoire.crd.ge.com>
barnett@grymoire.crd.ge.com (Bruce Barnett) writes:

| >   In article <1990Oct12.025833.13376@cubmol.bio.columbia.edu>
| > ping@cubmol.bio.columbia.edu (Shiping Zhang) writes: 
| 
| >>ftp genbank.bio.net << END
| >>ftp
| >>ident
| >>ls
| >>quit
| >>END
| 
| In article <7219@muffin.cme.nist.gov> libes@cme.nist.gov (Don Libes) writes:
| 
| >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. 
| 
| News to me. I have always done this, which works fine.
| 
| set HOST=`hostname`
| set SOURCE=machine.edu
| set temp=/tmp/file
| ftp -n $SOURCE <<END
| user anonymous $HOST
| get pub/file $temp
| quit
| END

(echo "user anonymous"; echo "${USER-${LOGNAME}}@`hostname`"; echo dir; echo quit) | \
	ftp uunet.uu.net
--
Michael Meissner	email: meissner@osf.org		phone: 617-621-8861
Open Software Foundation, 11 Cambridge Center, Cambridge, MA, 02142

Do apple growers tell their kids money doesn't grow on bushes?

barnett@grymoire.crd.ge.com (Bruce Barnett) (10/13/90)

In article <MEISSNER.90Oct12152854@osf.osf.org> meissner@osf.org (Michael Meissner) writes:

>   (echo "user anonymous"; echo "${USER-${LOGNAME}}@`hostname`"; echo dir; echo quit) | \
>	   ftp uunet.uu.net

Try:

 (echo "user anonymous ${USER-${LOGNAME}}@`hostname`"; echo dir; echo quit) | \
	   ftp uunet.uu.net
--
Bruce G. Barnett	barnett@crd.ge.com	uunet!crdgw1!barnett

booker@network.ucsd.edu (Booker bense) (10/13/90)

In article <1990Oct12.025833.13376@cubmol.bio.columbia.edu> ping@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. Do you have the same
>problem if you try it? I'm working on a Sun-3 with os4.1. I appreciate
>it if anyone can point out the problem for me. Thanks.
>
># cut here 
>ftp genbank.bio.net << END
>ftp
>ident
>ls
>quit
>END

Ftp reads the password from /dev/tty there's no simple way to get
around this , however I would suggest you read the man page on netrc.
It allows you to put ftp in scripts.

-Booker C. Bense


/* benseb@grumpy.sdsc.edu */






.line fodder 

jik@athena.mit.edu (Jonathan I. Kamens) (10/14/90)

In article <BARNETT.90Oct12133123@grymoire.crd.ge.com>, barnett@grymoire.crd.ge.com (Bruce Barnett) writes:
|> In article <7219@muffin.cme.nist.gov> libes@cme.nist.gov (Don Libes) writes:
|> >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. 
|> News to me. I have always done this, which works fine.
|> 
|> set HOST=`hostname`
|> set SOURCE=machine.edu
|> set temp=/tmp/file
|> ftp -n $SOURCE <<END
|> user anonymous $HOST
|> get pub/file $temp
|> quit
|> END

  Don is correct when he says that there is no *shell* mechanism to get around
the problem of a program forcing a read from /dev/tty.

  However, you are correct when you point out that there is an *ftp* mechanism
for getting around the problem of *ftp in particular* forcing a read from
/dev/tty -- just invoke ftp with auto-login disabled (the -n option) and
then supply the password with the "user" command, so that ftp never prompts
for it.

  The other ftp mechanism for getting around the problem is to use a .netrc
files.

  Two other mechanisms for getting around the problem are using Don's "expect"
program (whose use he illustrated in his posting) and using Dan Bernstein's
"pty" program.  Personally, I'd choose pty in this particular case, not
because it's more fault-tolerant than expect (in this case, it isn't), but
rather because the original poster's shell script can be made to work with no
other modifications simply by changing this line:

    ftp genbank.bio.net << END

to this line:

    pty ftp genbank.bio.net << END

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710

jik@athena.mit.edu (Jonathan I. Kamens) (10/14/90)

In article <BARNETT.90Oct12154348@grymoire.crd.ge.com>, barnett@grymoire.crd.ge.com (Bruce Barnett) writes:
|> In article <MEISSNER.90Oct12152854@osf.osf.org> meissner@osf.org (Michael Meissner) writes:
|> >   (echo "user anonymous"; echo "${USER-${LOGNAME}}@`hostname`"; echo dir; echo quit) | \
|> >	   ftp uunet.uu.net
|>  (echo "user anonymous ${USER-${LOGNAME}}@`hostname`"; echo dir; echo quit) | \
|> 	   ftp uunet.uu.net

  Neither of these examples will work, unless you supply "-n" option to ftp. 
Bruce, you got that right in your original posting on this subject, but forgot
it here :-).

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8495			      Home: 617-782-0710

barnett@grymoire.crd.ge.com (Bruce Barnett) (10/15/90)

In article <1990Oct14.152950.29384@athena.mit.edu> jik@athena.mit.edu (Jonathan I. Kamens) writes:

>Neither of these examples will work, unless you supply "-n" option to ftp. 
>Bruce, you got that right in your original posting on this subject, but forgot
>it here :-).

Termcap! Foiled again! The script I sent by E-mail worked.

A lowly wizard was at the bottom of a 1000 foot well. Each posting to
USENET that is unique and correct allows the wizard to climb up three
feet. Each mistake or redundant posting causes the wizard to slide
back two feet........


Well, at least I gained a foot. :-)
--
Bruce G. Barnett	barnett@crd.ge.com	uunet!crdgw1!barnett

ping@cubmol.bio.columbia.edu (Shiping Zhang) (10/16/90)

In response to my post on the subject, many people either posted
on this group or mailed me directly. Their messages are very helpful
to me. I'm very grateful to their help. The posts have covered all
I got from email, so I'm not going to post a summary here, assuming
all of you who are interested in this subject read all the posts.
If anyone feels missing something, please mail to me, I'll mail
back whatever I know. Thanks again.

-ping

rogier@caligula.ec.bull.fr (Pierre Rogier) (10/16/90)

In article <1990Oct12.025833.13376@cubmol.bio.columbia.edu>,
ping@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. Do you have the same
|> problem if you try it? I'm working on a Sun-3 with os4.1. I appreciate
|> it if anyone can point out the problem for me. Thanks.
|> 
|> # cut here 
|> ftp genbank.bio.net << END
|> ftp
|> ident
|> ls
|> quit
|> END

ftp read passwd from /dev/tty and not from standard input

I use the following script :
ftp -n my_machine <<END
user ftp ident
ls
quit
END