🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #1477

Re: standard input to commands in a shell script

#1477
From: Don Libes
Date: Fri, 12 Oct 1990 16:37
30 lines
1407 bytes
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
Technical Details
Message-ID: <7219@muffin.cme.nist.gov>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!uunet!cme!libes
References: <1990Oct12.025833.13376@cubmol.bio.columbia.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!uunet!cme!libes
From: libes@cme.nist.gov (Don Libes)
Newsgroups: comp.unix.shell
Subject: Re: standard input to commands in a shell script
Message-ID: <7219@muffin.cme.nist.gov>
Date: 12 Oct 90 16:37:37 GMT
References: <1990Oct12.025833.13376@cubmol.bio.columbia.edu>
Reply-To: libes@cme.nist.gov (Don Libes)
Organization: National Institute of Standards and Technology
Lines: 30