Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Crons not running
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Crons not running

jhjh Member

I wonder if someone might be able to help me..

I'm running CentOS 5.9. If I look in the cron log, I can see that the cron.hourly is being executed with run-parts every hour. Great. Now, I write a small script to run some backups and place it in there (mysqldump in a for loop and a tarsnap). It is executable by everyone and completes in a few seconds when I run it manually.

I wait a few hours and can see it hasn't been run at all since I ran it manually. I check the cron log and messages, and there's nothing in either of them, although I can see run-parts is still running every hour. I ran run-parts manually and it backs up fine.

Any ideas why it isn't running automatically every hour?

Comments

  • flyfly Member
    edited September 2013

    paste the logs and cron script?

  • Google might be able too......

  • Sounds like you need a Cron-As-A-Service


    https://www.setcronjob.com/

  • Backup script:

    #!/bin/bash
    mysql_password='removed'
    file_path='/var/www/html'
    backup_path='/tmp/dumps'
    
    for database in $(mysql -p${mysql_password} -e 'SHOW DATABASES;'  --skip-column-name --batch)
    do
        mysqldump -p${mysql_password} ${database} > ${backup_path}/${database}.sql
    done
    tarsnap -c --keyfile /root/tarsnap-limited.key --cachedir /usr/tarsnap-cache -f server.loadingdeck.com-$(date +'%F')-$(date +'%H') /var/www/html /tmp/dumps /etc/php.ini /etc/ssl /etc/httpd/conf/httpd.conf
    rm -f ${backup_path}/*
    

    Cron log:

    Sep  4 13:30:01 server crond[29448]: (root) CMD (/usr/lib64/sa/sa1 1 1)
    Sep  4 13:40:01 server crond[29558]: (root) CMD (/usr/lib64/sa/sa1 1 1)
    Sep  4 13:50:01 server crond[29682]: (root) CMD (/usr/lib64/sa/sa1 1 1)
    Sep  4 14:00:01 server crond[29792]: (root) CMD (/usr/lib64/sa/sa1 1 1)
    Sep  4 14:01:01 server crond[29807]: (root) CMD (run-parts /etc/cron.hourly)
    Sep  4 14:10:01 server crond[30041]: (root) CMD (/usr/lib64/sa/sa1 1 1)
    Sep  4 14:20:01 server crond[30157]: (root) CMD (/usr/lib64/sa/sa1 1 1)
    Sep  4 14:30:01 server crond[30272]: (root) CMD (/usr/lib64/sa/sa1 1 1)
    Sep  4 14:40:01 server crond[30382]: (root) CMD (/usr/lib64/sa/sa1 1 1)
    Sep  4 14:50:01 server crond[30501]: (root) CMD (/usr/lib64/sa/sa1 1 1)
    
  • Did you chmod it to be executable? Did you include the right interpreter as hashbang?

  • Google you SAY!?

    @Conn8ct said:
    Google might be able too......

    Have you made sure your using the full path/to/mysqldump or including it as an environment variable.

    Have you tried restarting cron after adding mysqldump? (lack of errors means its not trying to execute it at all)

  • Paste your crontab

  • netomxnetomx Moderator, Veteran

    Service cron restart ?

  • @Frost & @netomx Yes I did

    @WebSearchingPro trying it now

    @joelgm:

    SHELL=/bin/bash
    PATH=/sbin:/bin:/usr/sbin:/usr/bin
    MAILTO=root
    HOME=/
    
    # run-parts
    01 * * * * root run-parts /etc/cron.hourly
    02 4 * * * root run-parts /etc/cron.daily
    22 4 * * 0 root run-parts /etc/cron.weekly
    42 4 1 * * root run-parts /etc/cron.monthly
    
  • DroidzoneDroidzone Member
    edited September 2013

    Is run-parts the name of your script?

    Try replacing it with /bin/bash /root/run-parts /etc/cron.hourly. I dont know what the coloumn root is doing there. On Debian, the correct line would be:

    42 4 1 * * /bin/bash /root/run-parts /etc/cron.monthly for the last line. I havent really delved into the cron man pages to a deep level, but that line should work on Debian at least. Change the path accordingly. If you prefix it with bash, the script does not even need to be executable.

  • /bin/bash /root/run-parts

    I think you mean

    /bin/bash /usr/bin/run-parts

    No?

  • netomxnetomx Moderator, Veteran

    Have you tried to put a simple: echo 0 > /root/myfile to Check if The script really works? Maybe it is executing but it may not find something and exits

  • @jhadley said:
    No?

    Use the correct path of run-parts, whatever it is.

  • Cool it's working now. I guess I just needed to add the paths to the commands in the script.

  • @jhadley said:
    Cool it's working now. I guess I just needed to add the paths to the commands in the script.

    root should've been getting emails with the 'command not found' error(s) :)

  • @jhadley said:
    Cool it's working now. I guess I just needed to add the paths to the commands in the script.

    Sweet :) Its always something simple when we think its something all complicated.

  • skaska Member
    edited September 2013

    That's why you begin bash-scripts with

    #!/bin/bash
    PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
    export PATH
  • @WebSearchingPro said:
    Sweet :) Its always something simple when we think its something all complicated.

    Never a truer statement!

  • run-parts doesn't work with scripts that contain a period in their name. Just putting it out there in case someone else finds this thread.

    Thanked by 1netomx
Sign In or Register to comment.