Unix Scripting
-
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?
-
Answer:
http://expect.nist.gov/ 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 http://www.google.com/search?q=expect+ftp&btnG=Search&hl=en&lr=
mkultra at Ask.Metafilter.Com Visit the source
Other answers
Yep. You want expect.
kindall
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 <<EOFcd /some/directorymget *EOFEverything from the first EOF to the second will be supplied as the standard input to the program "ftp"
gds
If you are a Perl person there is a nice http://search.cpan.org/~rgiersig/Expect-1.15/Expect.pod 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.
harmfulray
Is use of the proprietary FTP application a requirement? If not, you could use Perl's http://search.cpan.org/~gbarr/libnet-1.19/Net/FTP.pm. I've used it to automate ftp transmissions on a number of machines.
bachelor#3
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.
mkultra
The easiest way to automate ftp transfers is to use http://www.mavetju.org/unix/netrc.php.
Deepspace
Whoa. Banks are still using FTP? Um... which bank?
Caviar
Related Q & A:
- Is there any functional-like Unix shell?Best solution by Super User
- Unix tools: what if a file is named minus something?Best solution by Super User
- What are the test automation tools that use perl as the scripting language??Best solution by Yahoo! Answers
- What does a Unix System Administrator do?Best solution by eHow old
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.