Crontab for automated backup --> not running
Hello,
I've created a script that will automatically back-up logs, www files and mysql database to dropbox and when I run it from shell it works as a charm. However, I also added it to /etc/crontab: 0 3 * * * root sh /var/scripts/serverbackup.sh This should run every day at 3AM, but it doesn't. Service crond status says that it's running. When I check cron logs, I can only see log entries related to the cron.daily, cron.hourly,... files. I'm running this on CentOS. What's my noob mistake :)? |
What des the script look like?
Just a guess, but the most common mistake here is neglecting to specify full paths to whatever commands you are using in the script. So, for example, you have to write Code:
/usr/bin/mysqldump whatever > sql_backup Code:
mysqldump whatever > sql_backup |
Here's the script. Does this mean that I have to use the full path for all commands (sh, tar, mkdir,...)?
Code:
#!/bin/bash |
Quote:
Alternatively, you may try to set the PATH variable in the begining of the script. |
You can simply make an crontab entry like:
Code:
~$ su - root |
If I understand correctly, you are saying that cron doesn't use the same shell as root would and therefore needs exact paths, because the command paths are for example unknown in that shell.
But this would mean that I don't only have to change those few commands in serverbackup.sh, but also in the underlying script dropbox_uploader.sh, and that is not quite the compact script that serverbackup.sh is. So I understand there is the different solution suggested by shivaa and millgates (in the end of that post) where I manually set some path somewhere, but I don't quite understand that. Since this is the noob forum, can I ask you to tell me exactly what to add where and what the meaning of it is? Especially shivaa's crontab alternative is Chinese to me. |
Quote:
Quote:
[code]# echo $PATH[/quote] Then you can place PATH=foo at the beginning of your script(s) or as the first line in your crontab. The PATH of my Rasberry Pi looks like the following: Code:
pi@raspbmc:~$ echo $PATH |
See millgates post(#4),
So su to root and find out the root user's path variable using Code:
env | grep PATH Code:
#!/bin/bash Code:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games Code:
chmod +x /var/scripts/serverbackup.sh |
Quote:
TRY THIS in /etc/crontab 0 3 * * * root /bin/sh /var/scripts/serverbackup.sh |
I completely understand what all of you wrote and I can implement it without a problem, yet the script still doesn't run automatically.
I'll post the content of /etc/crontab and /var/scripts/serverbackup.sh: Code:
SHELL=/bin/bash Code:
#!/bin/bash |
Try redirecting stderr to a file.
Code:
00 03 * * * /bin/sh /var/scripts/serverbackup.sh 2>>/tmp/serverbackup.err |
I have a feeling crontab is just not being executed. I tried your line, which didn't output anything to that file. Then I tried this line:
* * * * * env > /tmp/env.output and then also this one: * * * * * /bin/env > /tmp/env.output Which also did not output to that file. But service crond status says it's running... |
the look at the cron logs, typically they will be located in /var/log/cron you will see what is there.
|
Hurray! It works :). In the last edits I left out username variable in the crontab lines. Thanks to all!
|
post exactly what you did to fix this issue so others who might have simular issues in the future can refer to this thread.
Thank you and congratulations. |
All times are GMT -5. The time now is 03:29 AM. |