Find the answer to your Linux question:
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. ...
  1. #1
    Just 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

  2. #2
    Linux 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

  3. #3
    Just Joined!
    Join Date
    Mar 2007
    Posts
    8
    do you mean this...

    50 15 * * * /path/file

    or do you mean my bash script?

  4. #4
    Linux Enthusiast
    Join Date
    Aug 2006
    Posts
    631
    What I mean is, if you have a line like this in your cron file:

    Code:
    50 15 * * * /path/`date "+%Y%m%d"`.txt
    you must escape the % character like:

    Code:
    50 15 * * * /path/$(date +\%Y\%m\%d).txt
    Regards

  5. #5
    Just 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.

  6. #6
    Linux Guru anomie's Avatar
    Join Date
    Mar 2005
    Location
    Texas
    Posts
    1,692
    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.

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

  8. #8
    Just 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...