Page 1 of 3 123 LastLast
Results 1 to 10 of 28

Thread: cron job(s) not running

  1. #1

    Cool cron job(s) not running

    Hi all,

    I am having an issue with my cron jobs not running, so my /etc/crontab looks like this:

    59 23 * * * root /srv/script

    This hasn't run for the last three days, the script does a SQL backup, so what I done was created a cron job like the below:

    00 09 * * * env > /tmp/env.output

    But this file is never created, I have run the command in terminal to confirm that is OK, I've also checked that the cron service is running.

    Is there a log file I can review to see why this failed?

    Thanks!

  2. #2
    Join Date
    May 2012
    Location
    Finland
    Posts
    2,002

    Default Re: cron job(s) not running

    Does your script have shell properly defined by using #!/bin/sh at the start and are you sure the script has executable bit set?
    .: miuku #suse @ irc.freenode.net
    :: miuku@opensuse.org

    .: h​ttps://download.opensuse.org/repositories/home:/Miuku/

  3. #3
    Join Date
    Feb 2009
    Location
    Spain
    Posts
    25,547

    Default Re: cron job(s) not running

    On 2014-09-08 12:16, poobear85 wrote:

    > Is there a log file I can review to see why this failed?


    /var/log/messages

    And *mail*.

    --
    Cheers / Saludos,

    Carlos E. R.
    (from 13.1 x86_64 "Bottle" at Telcontar)

  4. #4

    Default Re: cron job(s) not running

    Hi,

    Yes it does, I used the below command to set the executable:

    sudo chmod +x scriptname

    Thanks,

  5. #5

    Default Re: cron job(s) not running

    Also to note if I run the script this works as expected.

  6. #6

    Default Re: cron job(s) not running

    Quote Originally Posted by robin_listas View Post
    On 2014-09-08 12:16, poobear85 wrote:

    > Is there a log file I can review to see why this failed?


    /var/log/messages

    And *mail*.

    --
    Cheers / Saludos,

    Carlos E. R.
    (from 13.1 x86_64 "Bottle" at Telcontar)
    The script has run the commands, so the schedule is working but it hasn't created the file expected, would anyone be able to help?

    Code:
    Sep  8 11:50:01 localhost /USR/SBIN/CRON[6594]: (root) CMD (/srv/Backups/MySQL/SQLBackup)
    Sep  8 11:50:01 localhost sudo:     root : TTY=unknown ; PWD=/root ; USER=root ; COMMAND=/usr/bin/touch backupfile20140908.sql
    Sep  8 11:50:01 localhost sudo:     root : TTY=unknown ; PWD=/root ; USER=root ; COMMAND=/bin/chmod 777 backupfile20140908.sql
    Sep  8 11:50:01 localhost sudo:     root : TTY=unknown ; PWD=/root ; USER=root ; COMMAND=/bin/chown wwwrun backupfile20140908.sql
    Script is below:

    Code:
    #!/bin/sh
    
    
    sudo touch backupfile`date +%Y%m%d`.sql
    sudo chmod 777 backupfile`date +%Y%m%d`.sql
    sudo chown wwwrun backupfile`date +%Y%m%d`.sql
    mysqldump --hex-blob --skip-comments --socket /tmp/mysql.sock -h 127.0.0.1 -u USERNAME -PASSWORD DATABASE > backupfile`date +%Y%m%d`.sql

  7. #7

    Default Re: cron job(s) not running

    Use absolute path and capture stderr too in env.out

    Code:
    00 09 * * * /usr/bin/env > /tmp/env.output 2>&1
    Most likely the commands/executable in your script needs absolute path too, or it might have something to do with the sudo too .
    "Unfortunately time is always against us" -- [Morpheus]

    .:https://github.com/Jetchisel:.

  8. #8
    Join Date
    Aug 2010
    Location
    Chicago suburbs
    Posts
    12,162
    Blog Entries
    3

    Default Re: cron job(s) not running

    Quote Originally Posted by poobear85 View Post
    Script is below:

    Code:
    #!/bin/sh
    
    
    sudo touch backupfile`date +%Y%m%d`.sql
    sudo chmod 777 backupfile`date +%Y%m%d`.sql
    sudo chown wwwrun backupfile`date +%Y%m%d`.sql
    mysqldump --hex-blob --skip-comments --socket /tmp/mysql.sock -h 127.0.0.1 -u USERNAME -PASSWORD DATABASE > backupfile`date +%Y%m%d`.sql
    Try adding an appropriate "cd" command near the beginning. The RPM instruction (Read the Programmer's Mind) is not working.
    openSUSE Leap 15.1; KDE Plasma 5;

  9. #9

    Default AW: Re: cron job(s) not running

    Quote Originally Posted by poobear85 View Post
    TScript is below:

    Code:
    #!/bin/sh
    
    
    sudo touch backupfile`date +%Y%m%d`.sql
    sudo chmod 777 backupfile`date +%Y%m%d`.sql
    sudo chown wwwrun backupfile`date +%Y%m%d`.sql
    mysqldump --hex-blob --skip-comments --socket /tmp/mysql.sock -h 127.0.0.1 -u USERNAME -PASSWORD DATABASE > backupfile`date +%Y%m%d`.sql
    Why are you using "sudo"?
    The script is run as root anyway, no?

    And you should "cd" to the directory whery you want to create the file, as someone else mentioned while I wrote this...
    The file probably got created somewhere where you did not expect it...
    Last edited by wolfi323; 08-Sep-2014 at 04:42.

  10. #10

    Default Re: cron job(s) not running

    Just keep in mind you need to check if the directory exist before you cd from a script and also exit immediately if the directory does not exist. Why? just a simple cd will bring you to "$HOME" in this case /root. It is not always intended/accepted specially if it involve rm .

    With an existing directory it is fine. (or variable is not empty)

    Code:
    jetchisel@Localhost:~> mydir=/tmp
    
    jetchisel@Localhost:~> cd "$mydir"
    
    jetchisel@Localhost:/tmp>
    Without an existing directory it is not. (or variable is empty)

    Code:
    jetchisel@Localhost:/tmp> mydir=
    jetchisel@Localhost:/tmp> cd "$mydir"
    jetchisel@Localhost:~>
    Just imagine running an rm after the cd, then the next step would be restoring your "$HOME" directory from backup.
    "Unfortunately time is always against us" -- [Morpheus]

    .:https://github.com/Jetchisel:.

Page 1 of 3 123 LastLast

Tags for this Thread

Posting Permissions

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