MoonChild Posted April 7, 2003 Report Share Posted April 7, 2003 So here is how I want to work... using BASH Start the script... 1. fetch a file using wget 2. run another program to process the file I got from wget 3. run sftp to upload the result Any suggestions and pointers? I know how to run programs through BASH... What I want is: How to make the script wait until wget finishes, how to make it wait until the processing program finishes and how to get sftp to work with it. I know there is delay until the server asks for a password, and there are local and remote commands. Any help welcomed and appreciated Quote Link to comment Share on other sites More sharing options...
aru Posted April 7, 2003 Report Share Posted April 7, 2003 If your run all your programs (wget, proccess program, and sftp) in the foreground, there will be no problem at all. The script wont run anything else untill the current proccess is finished. If you give us more details on what are you trying to do, we'll be able to give more concise help :) Quote Link to comment Share on other sites More sharing options...
MoonChild Posted April 7, 2003 Author Report Share Posted April 7, 2003 so let me see if I got this straight... #!/bin/bash wget http://...../data.txt & process data.txt & sftp ..... data.txt & Will this do all I need to do? Quote Link to comment Share on other sites More sharing options...
Cannonfodder Posted April 7, 2003 Report Share Posted April 7, 2003 Looks like it, although I would drop the & and put some checks in to make sure the file actually came down. You can also add a parameter so you can run the bash file with a parameter and get any specific file rather than recoding the same file. Quote Link to comment Share on other sites More sharing options...
qnr Posted April 7, 2003 Report Share Posted April 7, 2003 aru knows much more about it than me, but if I were doing it, I'd end up using &&, but that might be because I'm braindead. Quote Link to comment Share on other sites More sharing options...
MoonChild Posted April 7, 2003 Author Report Share Posted April 7, 2003 Found it... A nice little program called expect... Try autoexpect too... Both have man pages Quote Link to comment Share on other sites More sharing options...
aru Posted April 7, 2003 Report Share Posted April 7, 2003 Moonchild, putting & at the end of each command means sending them into the background, which is AGAINST my advice. aru knows much more about it than me, but if I were doing it, I'd end up using &&, but that might be because I'm braindead. I would also do it using && (with the backslash) at the end of each command, which means that if and only if the previous command went right (return status 0) then run the following command. Note about wget: wget returns 0 when it downloads something, and non 0 when it is unable to download, and that 'something' could be an error page. So I would make checks on the document you downloaded to see if it is right instead of a symple "&&". The script I posted here does things pretty close to the ones you want, so maybe you'd like to take a look to it to get some ideas ;) Quote Link to comment Share on other sites More sharing options...
MoonChild Posted April 8, 2003 Author Report Share Posted April 8, 2003 aru... thanks for your reply... I will do the && trick... I managed to get the script up and running (finally!!!) Of course, I only have minimal error checking for all now but here is the idea... 1. Perl script on the web collects data... 2. A bash script: a. Runs wget to retrieve data b. If new data are found, the backup old marker file and create a new c. Render a new image d. Run an expect script to connect with sftp to the server: i. Use an SFTP batch file to update necessary things e. exit 3. A cron job to run the bash script every 2 hours, every day. Wow me! I don't believe I did this! Anyone want to check what it does? http://students.washington.edu/michalis/ge...aphia/guestMap/ This is an early alpha version of the website, don't do any stress testing please? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.