I'm writing a bash script to download a logfile from a site, archive it, then upload the archive to the site. I want the script to stop if the file doesn't download correctly, and I think I've accomplished this. (i.e. it works right when I set it up to download a non-existent file.) Question: will ftp always return an error if the file is downloaded incorrectly or incompletely? This is important, because the last part of the script will replace the file on the ftp server with a blank file of the same name. I don't want to wipe out the original logfile if I don't have it all. (secondary question: Is there a way to pass the "delete" argument without using the interactive shell?) Here's what the first section of the script looks like. Third question: If I set this up to run as a cron job, what happens to my echo messages? Will they appear in /var/log/messages? #download logfile if ftp ftp://user:password@ftp.site.net/logfile.log; then echo echo "File has been downloaded" echo else echo "Download failed" exit fi Thanks, Greg
Gregory> I'm writing a bash script to download a logfile from a site, Gregory> archive it, then upload the archive to the site. I want the Gregory> script to stop if the file doesn't download correctly, and I Gregory> think I've accomplished this. (i.e. it works right when I set Gregory> it up to download a non-existent file.) Can't you run a script on the remote site? That would make the problem trivial. Also, you might want to check and see if your site (if you don't have full control) offers the ability to automatically rotate logs for you, which would make things much simpler all around. Gregory> Question: will ftp always return an error if the file is Gregory> downloaded incorrectly or incompletely? Nope, I don't think it will. You might try to use wget instead. Also, I'd try to download the file, then re-download it and see if the files are the same. If not, then you have a problem. It's a question of whether you're willing to lose logging information from your ftpd server. If you can lose some data. then what you're proposing should work. Gregory> This is important, because the last part of the script will Gregory> replace the file on the ftp server with a blank file of the Gregory> same name. I don't want to wipe out the original logfile if I Gregory> don't have it all. It's hard to do this, because in the time between you download the file, it might log a download (such as the FTP getting the log file itself!) and you'll miss details. Again, look for a solution where you can get the remote site to do the log rotation for you, since with the help of the ftp server, you can make sure you get a clean and consistent log file. Gregory> (secondary question: Is there a way to pass the "delete" Gregory> argument without using the interactive shell?) Not sure. You shouldn't have to anyway, just upload a zero length file over the log file and you'r eall set. Gregory> Here's what the first section of the script looks like. Third Gregory> question: If I set this up to run as a cron job, what happens Gregory> to my echo messages? Will they appear in /var/log/messages? You should look into using 'expect' to do all this work for you, it's the tool to use to automate a manual process. John
participants (2)
-
Gregory Avedissian
-
John Stoffel