Results 1 to 8 of 8
I have a bash script that creates a back up of my databases. In this script it creates a directory for the day, then puts the back-ups in that directory. ...
- 03-12-2007 #1Just Joined!
- Join Date
- Mar 2007
- Posts
- 8
cron job mkdir
I have a bash script that creates a back up of my databases. In this script it creates a directory for the day, then puts the back-ups in that directory. When I run the script as root, it works fine. I put it into roots crontab and it works if the directory is already created, however if the directory isn't created it won't work. Any ideas? thanks
- 03-12-2007 #2Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
Hi flann,
Welcome to the linuxforums,
Can you show us the command line of your crontab?
The common mistake is the use of unescaped % in a date command.
Regards
- 03-12-2007 #3Just Joined!
- Join Date
- Mar 2007
- Posts
- 8
do you mean this...
50 15 * * * /path/file
or do you mean my bash script?
- 03-12-2007 #4Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
What I mean is, if you have a line like this in your cron file:
you must escape the % character like:Code:50 15 * * * /path/`date "+%Y%m%d"`.txt
RegardsCode:50 15 * * * /path/$(date +\%Y\%m\%d).txt
- 03-12-2007 #5Just Joined!
- Join Date
- Mar 2007
- Posts
- 8
i didn't know that, thanks. My file doesn't have a date in it though. The cron job runs fine if I've already created the directory. I think that the problem is the bash script that is attempting to create the directory doesn't like the fact that there is a cron job running it. If i run the bash script as root it runs fine, and will also create the directory fine. its only when the cron job runs it.
- 03-13-2007 #6
Cron has a limited PATH, which is the cause of most problems like this.
It would help if you posted your crontab (crontab -l) entry and the script itself. Put them in code tags so that they're readable.
- 03-13-2007 #7Linux Enthusiast
- Join Date
- Aug 2006
- Posts
- 631
As anomie mentioned, cron has a limited path so use your command with the full path or set the PATH variable in your crontab.
Regards
- 03-13-2007 #8Just Joined!
- Join Date
- Mar 2007
- Posts
- 8
that did it. In my bash script I was using the relative path to make the directory. I set it to the absolute path and it worked great. Thank you all


Reply With Quote