Cron runs my script but script doesn't do anything, something to do with mail error??? "got status 0x004b#012"

16,929

Solution 1

You should provide the full path to rake in the cron line. Something like:

/sbin/rake or wherever it actually lives.

If the path that rake lives in isn't in you root user path it won't be able to run.

If it is mail you should see something in the mail log. Check there.

Solution 2

When you dealing with cron always consider environment variables. You'd better run bash script which imports environment variables (source) and run your command.

Share:
16,929

Related videos on Youtube

Daniel Upton
Author by

Daniel Upton

Updated on September 17, 2022

Comments

  • Daniel Upton
    Daniel Upton over 1 year

    I have a seriously weird problem with one of the Ubuntu 10.10 web servers I administer.

    I wrote a script using ruby and rake to run some tar commands and do a mysqldump of the databases. I've installed an entry in the root users crontab like so:

    0 0,12 * * * /bin/bash -l -c 'cd /my/script/path && rake backup:everything'
    

    This is working perfectly on one of the servers. However on the other this doesn't actually seem to execute whats in my script.

    I know it's getting called for definite because when I run

    grep CRON /var/log/syslog
    

    it returns:

    Mar 22 12:00:01 ServerName CRON[10273]: (root) CMD (/bin/bash -l -c 'cd /my/script/path && rake backup:everything')
    

    However it's definitely not doing whats in that script.

    When I directly run the script like this:

    cd /my/script/path && sudo rake backup:everything
    

    It works perfectly.

    Also I did this in the crontab of both servers:

    0 0,12 * * * /bin/bash -l -c 'cd /my/script/path && rake backup:everything >> output.txt'
    

    (as in the script I'm doing a "puts 'backing up x folder'" every so often)

    On the server where the cron job is working it creates the output.txt file and puts the expected output in there like "Beginning backup" etc.

    However on the server where it isn't working it only creates the file but leaves it empty. But when I copy the command from the syslog again and run it manually:

    sudo /bin/bash -l -c 'cd /my/script/path && rake backup:everything >> output.txt'
    

    It works fine and the output is as expected.

    I may be clutching at straws now but could it be anything to do with this:

    CRON[10271]: (root) MAIL (mailed 55 bytes of output but got status 0x004b#012)
    

    This appears in the syslog after every cron call. I only really have this cron job and another small one to update the system clock, but from the looks of it none of them are working correctly.

    Is an incorrect mail configuration killing my cron jobs? Is that even possible?

  • Daniel Upton
    Daniel Upton about 13 years
    Beautiful.. Thanks, I forgot the server it wasn't working on is used primarily for hosting ruby on rails applications while the other is used for PHP.. so i recently installed ruby and rake in the default locations on the PHP server just for this script and i must have done it differently for rails.. because "which rake" on the rails server returns: /usr/local/bin/rake and on the PHP server returned /usr/bin/rake.. Anyway.. I'm boring you! thanks!
  • Mike
    Mike about 13 years
    Glad I could help out!