Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

share|improve this question
    
Have you tried checking cron's status: service cron status If it's not running, you can start it with service cron start –  Steve Kroon Aug 16 '12 at 8:18

2 Answers 2

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|improve this answer
    
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 Aug 12 '12 at 17:36
    
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. –  DaMadBoy Aug 12 '12 at 19:52
    
Happy to help & contribute. –  exIT Solutions Aug 13 '12 at 4:51

If your script are running from interactive terminal but not from crontab, this is typical of an environment problem.

Cron runs your programs with an almost empty environment.

In your crontab, try adding >/tmp/script.log 2>&1 at the end of your scripts to catch the errors in a logfile.

You can also try to run your script with env -i to make sure they run properly with an empty environment. (env -i /you/script.sh)

You may have to add some entries in the PATH environment variable.

share|improve this answer
    
I tried adding the log like you suggested: 00 5 * * * root /etc/cron.pw/news5.sh >/tmp/script.log 2>&1 00 6 * * * root /etc/cron.pw/news6.sh >/tmp/script.log 2>&1 Unfortunately no log file was generated and 3 announcements should have run in the time that I modified the file till now. Did I do it correctly? I have to admit I'm fairly new to linux so unsure if I am doing it right. –  DaMadBoy Aug 12 '12 at 18:51

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.