user3199027
user3199027

Reputation: 31

Script does not run under cron but runs manually again

I am very sorry for asking this again, but I've tried all advices. I have 2 scripts in /var/TPbackup_script/. This is the first one:

mysqldump -u root -pPASSWORD teampass > /var/TPbackups/TPbackup_$(date +"%Y-%m-%d").sql

Corresponding cronjob in /etc/crontab

20 9    * * *   root    sudo sh /var/TPbackup_script/TPbackup_script

This script works in crontab. All is good. The second script does not run:

s3cmd sync /var/TPbackups s3://PwdMgmt

Corresponding cronjob in /etc/crontab:

25 9   * * *   root    sudo sh /var/TPbackup_script/TPsyncS3_script

This one fails. If i run it manually in terminal:

sudo sh /var/TPbackup_script/TPsyncS3_script

then it works perfectly. What i tried:

1) Trying to add shebang #!/bin/sh to the beginning of the script
2) Renaming script to TPsyncS3_script.sh
3) I have added script into cron.daily and it was in the list of daily cron tasks (i see it with command run-parts --test /etc/cron.daily)
No success.
Here is my /etc/crontab file:

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# m h dom mon dow user  command
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
16 9    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
20 9    * * *   root    sudo sh /var/TPbackup_script/TPbackup_script
25 9    * * *   root    sudo sh /var/TPbackup_script/TPsyncS3_script.sh > /var/TPbackup_script/sync_log.txt
#

All permissions on scripts were set with sudo chmod 777.
And by the way. sync_log.txt was created after cronjob, but it's empty.
Any help is appreciated

Upvotes: 3

Views: 2752

Answers (2)

cpmilez
cpmilez

Reputation: 21

Had the same problem. Solved this by adding the option to specify the location of the s3cfg:

--config /root/.s3cfg

e.g:

s3cmd sync --config /root/.s3cfg /var/TPbackups s3://PwdMgmt

Upvotes: 2

Slava Elantsev
Slava Elantsev

Reputation: 81

I had a similar problem. Try to run your script using root's crontab. do: sudo crontab -e

Add your script and try again. It worked for me :)

Upvotes: 0

Related Questions