LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   one script does not work at crontab (https://www.linuxquestions.org/questions/linux-newbie-8/one-script-does-not-work-at-crontab-825694/)

windstory 08-11-2010 11:42 PM

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.

chrism01 08-12-2010 01:18 AM

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.

jrosco 08-12-2010 01:51 AM

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

windstory 08-12-2010 07:15 PM

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)

chrism01 08-12-2010 10:11 PM

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...

windstory 08-13-2010 12:11 AM

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/

jrosco 08-13-2010 12:24 AM

run
Code:

which rsync
and see where the rsync executable is located

JC

windstory 08-13-2010 02:56 AM

jrosco/ Thanks!
"rsync_backup.sh" works fine!


All times are GMT -5. The time now is 07:42 PM.