Unix Scripting
December 15, 2004 11:37 AM   Subscribe

Unix scripting question- how do I automate an interactive command-line application? [MI]

I'm using a proprietary FTP application to transmit a file each day, and pick up a receipt of the prior day's file. The application accepts various command line switches that let me execute the upload as a single command, which is fine. Unfortunately, I don't know the name of the receipt file, so I need to log in and do an "mget *" within the application to reliably get the receipt file. Unfortunately, the download parameter I would normally use won't take a wildcard.

So, the meat of my question is, how do I launch a command line application and feed it a command once it starts up, via a shell script?
posted by mkultra to Computers & Internet (8 answers total)
expect is great for this sort of thing. It even has a learn mode that lets you do some tasks then creates a script ( some editing required ).

Google has lots of examples
posted by stuartmm at 11:43 AM on December 15, 2004

Yep. You want expect.
posted by kindall at 11:57 AM on December 15, 2004

I agree, expect is best for general use. Your application sounds simple enough that you might get away with, something more lightweight like a "here-document" to supply the input. Using bash syntax you could write:
ftp <<EOF
cd /some/directory
mget *
Everything from the first EOF to the second will be supplied as the standard input to the program "ftp"
posted by gds at 12:02 PM on December 15, 2004

If you are a Perl person there is a nice Expect module available that will let your Perl script be the framework and do the text manipulation while making calls to Expect to send commands and retrieve their results.
posted by harmfulray at 12:08 PM on December 15, 2004

Is use of the proprietary FTP application a requirement? If not, you could use Perl's FTP module. I've used it to automate ftp transmissions on a number of machines.
posted by bachelor#3 at 12:20 PM on December 15, 2004

Is use of the proprietary FTP application a requirement?

Yeah, I'm dealing with a bank. You wouldn't believe the hoops I have to jump through...

Thanks, everyone. Expect seems to be exactly what I'm looking for. gds- EOF is a good thought, but it throws off the results of some of the parameters I have to throw at the app.
posted by mkultra at 12:41 PM on December 15, 2004

The easiest way to automate ftp transfers is to use .netrc.
posted by Deepspace at 3:36 PM on December 15, 2004

Whoa. Banks are still using FTP?

Um... which bank?
posted by Caviar at 11:23 AM on December 16, 2004

« Older Should I be worried about my daughters' weight...   |   UK iPod Newer »
This thread is closed to new comments.