crontab Suddenly Stopped Working

15,129

1. Note down all the cron jobs for all users including root, for example:

To list the root's crontab

sudo crontab -l

To list your crontab

crontab -l

2. Delete the crontab complete for all users using the following

To delete the root's crontab

sudo crontab -r

To delete your crontab

crontab -r

3. Restart the system

4. Place your jobs back into the cron (Preferably the root's cron) either by creating a text file then pointing cron to that file or manually.

To set up manually

sudo crontab -e

To point cron to a text file

sudo crontab <filename>

Logically, preferably entered in the order of occurance. For example if you have a job that runs before another (in time) place that above.

Remember that the cron file or crontab must have entries in the following format

m h dom mon dow full path command

For example shutdown at 2:30PM ever day of week except weekends would be

30 14 * * 2,3,4,5,6 /sbin/shutdown

Another example run a script file (test.sh - located in /usr/local/myScripts folder) every monday at 2:00AM would be

0 2 * * 2 /usr/local/myScripts/test.sh

I had the same problem with cron, once and I remember reading in a forum that we need to delete the user's cron and restart the system then recreate it.

Share:
15,129

Related videos on Youtube

DaMadBoy
Author by

DaMadBoy

Updated on September 18, 2022

Comments

  • DaMadBoy
    DaMadBoy over 1 year

    Ok so here is my problem, I recently updated my server and change some jsp files which are used to do automatic announcements. The crontab has all the .sh files listed within it and the .sh files run the jsp files to display the announcements.

    After I finished updating the jsp files, I rebooted the server and ever since then the announcements have stopped running. I can run the .sh files via putty manually and they work perfectly fine so the changes I made to the jsp files are not the problem.

    I did some research before posting here and I checked the syslog for cron entries. Up until the point I rebooted my server the cron service was running as it should. Since the reboot there has been no entries in the syslog for cron.

    I've tried rebooting the server again, I also tried restarting the cron service, I also even tried stopping the service completely and starting it again with no effect. I can't figure out why the cron service would suddenly stop working as nothing to do with cron or any of the operating files were touched during the update of my server.

    Does anyone have any suggestions as to why it may have stopped working? I'm using Ubuntu Server 11.10

    • Steve Kroon
      Steve Kroon over 11 years
      Have you tried checking cron's status: service cron status If it's not running, you can start it with service cron start
  • DaMadBoy
    DaMadBoy over 11 years
    Thanks for the quick responses, I will give these a try during my servers next scheduled maintenance, which unfortunately wont be until Friday as I have players constantly connected to the server. I will let you know how it all turns out.
  • DaMadBoy
    DaMadBoy over 11 years
    I managed to fix it by stopping the cron service, deleting crontab, uploading an older crontab and start the cron service again. Thanks a lot for the help, couldn't have done it without it.
  • exIT Solutions
    exIT Solutions over 11 years
    Happy to help & contribute.