homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

I need help with a cron job - automatic ftp backup
attempting to use a cron job to back files up via ftp

 5:26 pm on Nov 30, 2007 (gmt 0)

I'm trying to automate the ftp-backup process on our mysql database box using cron and a shell script. For the purposes of testing theories I've given the script (/home/ftpscript.sh) 777 permissions. I can execute it as a logged in user with no problems and it performs its function perfectly every time, however I am unable to get it to run as a cron job.

The machine is running Fedora Core 5. When I use webmin to run the cron job manually (so I can get the output) I get the following:

ftp: u: unknown option

The cron is:

15 1 * * * bash /home/ftpscript.sh

so it will run at 1:15 every morning.

The content of ftpscript.sh are as follows (modified of course, #'s are the IP, adminuser and adminpassword are placeholders for the real user and pass):

cd /home/mysql-backups/
ftp -u ###.###.###.### <<!
quote user adminuser
quote pass adminpassword
cd /web/mysql-backups/
put backupfile.sql
put backupfile2.sql

What it seems like, is that I need to have the full path of ftp as it's defaulting to the copy at /usr/bin/ftp. When I log into the shell and run ftp -u [IP address] it works just fine, but if I run /usr/bin/ftp -u [IP address] I get the same erorr as is reported in the cron (ftp: u: unknown option). Any help on this would be greatly appreciated!




 7:17 pm on Nov 30, 2007 (gmt 0)

try "whereis ftp" to see if there is a path to another version of ftp.


 8:34 pm on Nov 30, 2007 (gmt 0)

I get:

ftp: /usr/bin/ftp /usr/share/man/man1/ftp.1.gz

when I use the command whereis ftp. So that only found the same version and the gzipped man page.



 8:36 pm on Nov 30, 2007 (gmt 0)

try using "whoami" to get the user of the cron job.
then try to run ftp under that user and see results what you get.


 9:14 pm on Nov 30, 2007 (gmt 0)

Another tip - you may want to gzip the sql files to make them smaller thus quicker for ftp-ing.

And if you are worried about security look into sftp so that you don't need to transmit unsecure login details.


 9:19 pm on Nov 30, 2007 (gmt 0)

In the cron editor I selected to run the job as root. When logged in as root, "ftp -u [IP]" works from the shell.

Just to be sure though, I created a new cron job and selected to run it as root as well. The new cron command was just "whoami" and the output was "root" so I know that the user selection function works at least.

Thanks for your help so far, I really appreciate it!

-Sean Hayes


 11:00 pm on Nov 30, 2007 (gmt 0)

try echoing and comparing the PATH variable for both environments.


 12:53 am on Dec 1, 2007 (gmt 0)

It *appears*, at least, that you only have one copy of "ftp" on your machine. So, looking at paths is not going to get you anywhere.

To be sure, first make sure your whereis database is up-to-date:

sudo updatedb

Then run the "whereis" again.

If you still only find one copy, the only thing I can think of is a command alias. Check your .profile, etc.

A good time to inject a bit of finger-wagging: if this is going over the Internet, remember that FTP is insecure. You are much better off using sftp. Then you can also set-up a public-private keypair, and you won't have to stick a password in the script.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved