Programming This 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.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
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.
 |
GNU/Linux Basic Guide
This 255-page guide will provide you with the keys to understand the philosophy of free software, teach you how to use and handle it, and give you the tools required to move easily in the world of GNU/Linux. Many users and administrators will be taking their first steps with this GNU/Linux Basic guide and it will show you how to approach and solve the problems you encounter.
Click Here to receive this Complete Guide absolutely free. |
|
 |
09-16-2004, 11:10 AM
|
#1
|
|
LQ Newbie
Registered: Sep 2004
Posts: 2
Rep:
|
FTP Script will not run from Cron
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?
Your help is appreciated.
Here is the crontab statement that I am using:
0 22 * * * /<user_home_dir>/scripts/nightly_ftp.sh &>/<user_home_dir>/log/ftp.log
Here is a copy of the script that I am executing.
#!/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.
I'm open to suggestions.
Thanks again.
|
|
|
|
09-16-2004, 12:45 PM
|
#2
|
|
Member
Registered: May 2002
Location: dracut MA
Distribution: Ubuntu; PNE-LE; LFS (no book)
Posts: 593
Rep: 
|
The fix should be simple enough:
for I in /<user_home_dir>/data/download/*.txt do
rm $I
done
if that causes problems, you can always try and escape the * character with \* (just a thought).
Aaron
|
|
|
|
09-16-2004, 01:43 PM
|
#3
|
|
LQ Newbie
Registered: Sep 2004
Posts: 2
Original Poster
Rep:
|
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?
All help appreciated.
|
|
|
|
09-16-2004, 02:54 PM
|
#4
|
|
Guru
Registered: Aug 2004
Location: Brisbane
Distribution: Centos 6.4, Centos 5.9
Posts: 15,021
|
try inserting
set -xv
before it gets to the ftp section. That will tell you in detail exactly what it's trying to do.
|
|
|
|
09-16-2004, 04:32 PM
|
#5
|
|
Senior Member
Registered: Jul 2004
Distribution: Slackware
Posts: 2,140
|
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
|
|
|
|
01-12-2006, 04:59 AM
|
#6
|
|
Member
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 12.04 - Server Ubuntu 12.04
Posts: 903
Rep:
|
Quote:
|
0 22 * * * /<user_home_dir>/scripts/nightly_ftp.sh &>/<user_home_dir>/log/ftp.log
|
Just an idea, did you use the username and password in front of your crontab
I'm looking at doing the same thing, using FTP to upload a group of files to another Server.
TT
|
|
|
|
01-12-2006, 05:46 AM
|
#7
|
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,211
Rep: 
|
a cron environment issue?
have you tried
. ~/.profile in the script?
try it on the at daemon.
batch
this works with the current environment.
|
|
|
|
01-12-2006, 05:51 AM
|
#8
|
|
Member
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 12.04 - Server Ubuntu 12.04
Posts: 903
Rep:
|
No I haven't try it, U kind of lost me there.unless U were taking to the other guy
TT
Last edited by tommytomato; 01-12-2006 at 05:52 AM.
|
|
|
|
01-12-2006, 06:04 AM
|
#9
|
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,211
Rep: 
|
well, talking to the OP of course!

|
|
|
|
01-12-2006, 07:08 AM
|
#10
|
|
Member
Registered: Sep 2004
Distribution: OpenSuSe
Posts: 153
Rep:
|
Well, I guess, if the log is showing that the connection was successful, the requirement of username password etc. shouldn't be the issue.
Probabaly you can increase the verbosity of the ftp session by adding some "-v" flags.
Code:
ftp -v -v -n <remote_ip_addr>
Billy's idea of trying this using "at" is also useful.
HTH
|
|
|
|
01-12-2006, 08:00 AM
|
#11
|
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,211
Rep: 
|
cron and ftp work fine for me.
Are you relying on .netrc?
man ftp
Code:
-n Does not attempt "auto-login" upon initial connection.
If auto-login is not disabled, ftp checks the .netrc
file in the user's home directory
Last edited by bigearsbilly; 01-12-2006 at 08:01 AM.
|
|
|
|
01-12-2006, 08:58 PM
|
#12
|
|
Member
Registered: Nov 2003
Location: Narrogin Western Australia
Distribution: GUI Ubuntu 12.04 - Server Ubuntu 12.04
Posts: 903
Rep:
|
Hi guys/gals
any of you people have a sample of a working FTP .sh script, I've just finshed working with FTP comands from the command line.
Code:
ftp> cd uploading
250 CWD command successful.
ftp> put database.sql
local: database.sql remote: database.sql
227 Entering Passive Mode (xxx,xx,xxx,xxx,62,95)
125 Data connection already open; Transfer starting.
226 Transfer complete.
607177 bytes sent in 19 seconds (31 Kbytes/s)
ftp> bye
421 Timeout (120 seconds): closing control connection.
I connected to my brothers machine 270km's from were I am so I know that FTP from the command line works.
TT
|
|
|
|
01-13-2006, 04:13 AM
|
#13
|
|
Senior Member
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,211
Rep: 
|
read the man page
make a .netrc file in HOME.
chmod .netrc to 600. (It won't work with go+r read permissions)
here you put a list of machines, users and passwords.
e.g:
Code:
machine ftp.vim.org
login anonymous
password billgates@google.com
macdef init
hash
prompt
machine blah
...
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.
|
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 11:38 AM.
|
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|