ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am trying to download, using ftp, a set of files on a nightly basis. The download runs like a champ when executed from the command line. I do have a .netrc file that works when I run it from the command line, but cron doesn't seem to use it. When cron tries to run the script, it hangs. I included the pertinent information below. Any thoughts on why the script hangs when being initiated from cron?
#!/bin/bash
# clear directory for new files
#rm /<user_home_dir>/log/ftp.log
rm /<user_home_dir>/data/download/*.txt
rm /<user_home_dir>/data/download/*.gz
# get the value of yesterday's date
. /<user_home_dir>/scripts/yesterday.sh `date +%m`/`date +%d`/`date +%Y`
# determine file name of image files
landFile=pics-land-$yesterday.tar
resFile=pics-residential-$yesterday.tar
comFile=pics-commercial-$yesterday.tar
multiFile=pics-multi-family-$yesterday.tar
# download latest listing files
ftp -n <ftpsite> <<End-of-Session
user <uid> <pwd>
get listings-commercial.txt.gz /<user_home_dir>/data/listings-commercial.txt.gz
get listings-land.txt.gz /<user_home_dir>/data/listings-land.txt.gz
get listings-multi-family.txt.gz /<user_home_dir>/data/listings-multi-family.txt.gz
get listings-residential.txt.gz /<user_home_dir>/data/listings-residential.txt.gz
get $landFile /<user_home_dir>/data/images/$landFile
get $resFile /<user_home_dir>/data/images/$resFile
get $comFile /<user_home_dir>/data/images/$comFile
get $multiFile /<user_home_dir>/data/images/$multiFile
bye
End-of-Session
mv listings* /<user_home_dir>/data/download
exit 0
And here is the information in the log file.
rm: cannot remove `/home/highland/data/download/*.gz': No such file or directory
09/14/2004
Connected to <remote addr> (<remote addr>).
220 FTP Server ready.
The file not found is no big deal, the date value shows that the yesterday script is executing correctly, and you can see that I'm connecting successfully to the remote site, but then the process just hangs.
Thanks for the reply, but I'm not sure how that addresses the issue.
The issue is not in clearing up the .txt files on the local machine.
The issue is getting the ftp script to execute from cron. As you can see from the log file excerpt, it connects to the remote machine, but for some reason it does not issue the "get" commands in the ftp script. I'm curious why those commands are not being issued after a successful login.
When I run it from the command line, the script runs just fine, and retrieves all of the files that I am requesting.
So why, when I run the script through cron, does it not issue the "get" statements in the ftp script?
Or did you try to send command from a cat pipe like :
cat <<END | ftp -n <adress>
user <uid> <pwd>
get listings-commercial.txt.gz /<user_home_dir>/data/listings-commercial.txt.gz
get listings-land.txt.gz /<user_home_dir>/data/listings-land.txt.gz
...
END
macdef init is a macro that's run on each login.
with this done, you can simply write a file of commands and
cat then into ftp. Or you can write more macros with macdef.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.