[SOLVED] Crontab for automated backup --> not running
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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
Does this mean that I have to use the full path for all commands (sh, tar, mkdir,...)?
Yes. Cron jobs are run in a limited environment, the $PATH variable is not set as it would be in your (root's) normal profile.
Alternatively, you may try to set the PATH variable in the begining of the script.
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.
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.
Correct, you either need to always use full path or you can try placing the PATH= in the first line of your crontab
Quote:
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.
to find the PATH or root, log into root and run the following command:
[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:
Distribution: RedHat Enterprise Linux Server Edition 5.5
Posts: 13
Rep:
Quote:
Originally Posted by Wover
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 ?
TRY THIS in /etc/crontab
0 3 * * * root /bin/sh /var/scripts/serverbackup.sh
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.