LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 10-23-2007, 07:13 AM   #1
Hynesm
LQ Newbie
 
Registered: Oct 2007
Location: Brisbane, Australia
Distribution: Fedora 7
Posts: 5

Rep: Reputation: 0
Crontab Backup


I hope this is the right topic for this, but here is my question.

I have written a script that will backup a file from my server to my local machine via FTP. When I run this script through the terminal it works, but when I set it as a cronjob it does not.

Code:
date=`date -I`
ftp -n <<EOT
open galacticpatrol.net
user username password
cd /private/backup/
lcd /root/GP_Backup/
get xbackup_$date.sql.gz
bye
EOT
Is there any reason why this works when I run it through terminal and it does not when I run it from the crontab?

Note: The file is saved as gp_backup.sh and is set to be executable. I have edited out the password and username.

Last edited by Hynesm; 10-23-2007 at 07:15 AM.
 
Old 10-23-2007, 07:36 AM   #2
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
It can work or not depending from many reasons. Is the crond daemon active? How did you specified the crontab entry? Is the script running but gives errors or is not running at all? You may do some checks to debug: first check the system mail looking for messages from the cron daemon. From your script I assume you're running it as root so you can open a terminal, login as root and launch the mail command. Second, you can try to redirect standard output and standard error in a log file to see if some useful message comes out, as in
Code:
5 10 * * * /root/bin/my_script.sh > /root/logfile 2>&1
just an example. Any further information may help to solve your issue.
 
Old 10-23-2007, 07:54 AM   #3
Hynesm
LQ Newbie
 
Registered: Oct 2007
Location: Brisbane, Australia
Distribution: Fedora 7
Posts: 5

Original Poster
Rep: Reputation: 0
I used the mail and got the following:

Code:
[root@localhost ~]# mail
Mail version 8.1 6/6/93.  Type ? for help.
"/var/spool/mail/root": 1 message 1 new
>N  1 logwatch@localhost.l  Tue Oct 23 20:17  43/1613  "Logwatch for localhos"
&
I am currently using the following crontab command:

Code:
*/5     *       *       *       *       /root/Galactic_Patrol_Backup/gp_backup.sh
It is set as every 5 minutes for testing reason, i will try the command you suggest now.
 
Old 10-23-2007, 08:25 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
Ok. No mail from the cron daemon. Redirecting standard output/error to a file will cause the file to be created when the cron job is executed, even if it remains empty. After this you can understand if the problem is related to the cron service or to the crontab itself, since it looks like the syntax of the script is correct.
 
Old 10-23-2007, 08:43 AM   #5
Hynesm
LQ Newbie
 
Registered: Oct 2007
Location: Brisbane, Australia
Distribution: Fedora 7
Posts: 5

Original Poster
Rep: Reputation: 0
I amended the crontab to include the script to log the file and waited till the cron had run. It did not create a file with a log in it.
 
Old 10-23-2007, 09:47 AM   #6
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,458

Rep: Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941Reputation: 1941
It looks like the cron daemon is not running. Please, can you post the output of the following commands?
Code:
ps -ealf | grep cron
/etc/init.d/cron status  # run this as root
The former should find a running process called crond (if any). The latter checks the status of the cron service. Anyway, what linux distro are you running on? You can also add this info in your LQ profile so it will appear in the sidebar on the left of your posts.
 
Old 10-23-2007, 10:45 AM   #7
trickykid
Guru
 
Registered: Jan 2001
Posts: 24,133

Rep: Reputation: 197Reputation: 197
Scripts should always include the full path to any executables as well, example, the ftp command. If you are getting logwatch emails, that's an indication that cron is running.
 
Old 10-23-2007, 08:14 PM   #8
Hynesm
LQ Newbie
 
Registered: Oct 2007
Location: Brisbane, Australia
Distribution: Fedora 7
Posts: 5

Original Poster
Rep: Reputation: 0
I am using Fedora 7 and I ran the code you provided and got the following output:

Code:
[root@localhost ~]# ps -ealf | grep cron
1 S root      2356     1  0  78   0 -  1335 -      Oct23 ?        00:00:00 crond
0 S root     32290 32267  0  85   0 -  1003 pipe_w 11:08 pts/0    00:00:00 grep cron
[root@localhost ~]# /etc/init.d/crond status  # run this as root
crond (pid 2356) is running...
I will update my profile now.
 
Old 10-23-2007, 09:12 PM   #9
Hynesm
LQ Newbie
 
Registered: Oct 2007
Location: Brisbane, Australia
Distribution: Fedora 7
Posts: 5

Original Poster
Rep: Reputation: 0
It seems to be working great now, thanks for all your help.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using RSync to backup a secondary off-site backup server pezdspencer Linux - Software 4 06-29-2007 03:40 PM
Backup with rsync and crontab gjblackford Linux - General 4 01-04-2007 08:53 AM
LXer: Scheduling Backup Jobs using at and crontab LXer Syndicated Linux News 0 04-22-2006 01:24 AM
system backup using crontab goodolday Linux - General 1 04-26-2005 04:28 PM
system-wide crontab in /etc/crontab ner Linux - General 2 11-18-2003 12:35 PM


All times are GMT -5. The time now is 06:32 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration