LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 08-11-2010, 11:42 PM   #1
windstory
Member
 
Registered: Nov 2008
Posts: 489

Rep: Reputation: 36
one script does not work at crontab


I made a rsync backup at crontab, but this rsync backup script does not work.

Quote:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/

# run-parts
01 * * * * root run-parts /etc/cron.hourly
02 4 * * * root run-parts /etc/cron.daily
22 4 * * 0 root run-parts /etc/cron.weekly
42 4 1 * * root run-parts /etc/cron.monthly
0 2,6,14,18 * * * root /root/backup_script/rsync_backup.sh
10 0,2,4,6,8,10,12,14,16,18,20,22 * * * root /root/backup_script/3.mysqldb_backup.sh
However "/root/backup_script/3.mysqldb_backup.sh" works.

Please let me know how to make rsync backup script works on crontab.

Thanks in advance.
 
Old 08-12-2010, 01:18 AM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
For a start we'll need to see the code and you'll have to tell us exactly what the symptoms of "does not work" are; we're not mind readers.
 
Old 08-12-2010, 01:51 AM   #3
jrosco
Member
 
Registered: Aug 2010
Location: Australia
Posts: 37

Rep: Reputation: 4
You should put your cronjobs in /var/spool/cron/root not /etc/crontab or edit with

Code:
crontab -e
Well thats how I was taught

Can you run the scripts from the commandline

Code:
/root/backup_script/rsync_backup.sh
It could be your permissions on that script are not correct, look in /var/log/cron for any errors. Like chrism01 said, you should post the code.

JC
 
Old 08-12-2010, 07:15 PM   #4
windstory
Member
 
Registered: Nov 2008
Posts: 489

Original Poster
Rep: Reputation: 36
jrosco/ Yes, I can run "rsync_backup.sh".

And "rsync_backup.sh" is this.

Quote:
#! /bin/bash
rsync -avr --delete --exclude lampp/tmp/* /opt/* /backup/opt/
rsync -avr --delete --exclude data/session/* /var/www/html/centos-vb/* /backup/centos-vb/
And the log part of cron is here.

Quote:
Aug 13 00:01:01 centos-vb crond[9222]: (root) CMD (run-parts /etc/cron.hourly)
Aug 13 00:10:01 centos-vb crond[9300]: (root) CMD (/root/backup_script/3.mysqldb_backup.sh)
Aug 13 01:01:01 centos-vb crond[9747]: (root) CMD (run-parts /etc/cron.hourly)
Aug 13 02:00:01 centos-vb crond[10295]: (root) CMD (/root/backup_script/rsync_backup.sh)
Aug 13 02:01:01 centos-vb crond[10312]: (root) CMD (run-parts /etc/cron.hourly)
Aug 13 02:10:01 centos-vb crond[10377]: (root) CMD (/root/backup_script/3.mysqldb_backup.sh)
Aug 13 03:01:01 centos-vb crond[10867]: (root) CMD (run-parts /etc/cron.hourly)
Aug 13 04:01:01 centos-vb crond[11424]: (root) CMD (run-parts /etc/cron.hourly)
Aug 13 04:02:01 centos-vb crond[11439]: (root) CMD (run-parts /etc/cron.daily)
Aug 13 04:02:01 centos-vb anacron[11443]: Updated timestamp for job `cron.daily' to 2010-08-13
Aug 13 04:10:01 centos-vb crond[11974]: (root) CMD (/root/backup_script/3.mysqldb_backup.sh)
Aug 13 05:01:01 centos-vb crond[12409]: (root) CMD (run-parts /etc/cron.hourly)
Aug 13 06:00:01 centos-vb crond[12694]: (root) CMD (/root/backup_script/rsync_backup.sh)
Aug 13 06:01:02 centos-vb crond[12708]: (root) CMD (run-parts /etc/cron.hourly)
Aug 13 06:10:01 centos-vb crond[12769]: (root) CMD (/root/backup_script/3.mysqldb_backup.sh)
Aug 13 07:01:01 centos-vb crond[13192]: (root) CMD (run-parts /etc/cron.hourly)
Aug 13 08:01:01 centos-vb crond[13743]: (root) CMD (run-parts /etc/cron.hourly)
Aug 13 08:10:01 centos-vb crond[13800]: (root) CMD (/root/backup_script/3.mysqldb_backup.sh)
 
Old 08-12-2010, 10:11 PM   #5
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
The default env in cron is minimal to say the last. Best practice is to always specify complete paths to all cmds & files used unless you KNOW that the cron env will handle them correctly.... or specify a new env at the top of the script...
 
Old 08-13-2010, 12:11 AM   #6
windstory
Member
 
Registered: Nov 2008
Posts: 489

Original Poster
Rep: Reputation: 36
chrism01/ I changed and added env in cron as follows, but still not worked.

Quote:
#! /bin/bash

export PATH=/usr/local/bin:/usr/bin:/bin

rsync -avr --delete --exclude lampp/tmp/* /opt/* /backup/opt/
rsync -avr --delete --exclude data/session/* /var/www/html/centos-vb/* /backup/centos-vb/
 
Old 08-13-2010, 12:24 AM   #7
jrosco
Member
 
Registered: Aug 2010
Location: Australia
Posts: 37

Rep: Reputation: 4
run
Code:
which rsync
and see where the rsync executable is located

JC
 
Old 08-13-2010, 02:56 AM   #8
windstory
Member
 
Registered: Nov 2008
Posts: 489

Original Poster
Rep: Reputation: 36
jrosco/ Thanks!
"rsync_backup.sh" works fine!
 
  


Reply



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
My BASH script work perfect when i run it manualy, but not when it run in the crontab roqarg Linux - Newbie 30 05-06-2010 01:37 PM
Runs Multiple shell script inside a main script using crontab srimal Linux - Newbie 4 10-22-2009 06:19 PM
Program initiated via python's os.system() doesn't work (when in crontab script) itmi Programming 3 03-03-2008 05:36 PM
grep does not work in crontab script blizunt7 Linux - General 5 08-24-2007 02:19 PM
Crontab does not work riotxix Linux - Software 15 12-14-2006 01:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:39 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration