LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 01-22-2012, 04:33 PM   #1
jamespetts
Member
 
Registered: Sep 2002
Location: UK
Distribution: Ubuntu 11.10
Posts: 121

Rep: Reputation: 16
Cron jobs not running on server (Ubuntu 11.10)


I am having trouble with cron jobs not running on a VPS that I am renting running Ubuntu 11.10. I rented the server to run as a public server for my fork of the popular open source transport simulation game "Simurans" (my fork being Simutrans-Experimental). The cron job is intended to run a script every minute which checks to see whether the server is still running, and, if it has stopped, restart it. I have also added a test cron job to check whether the problem is with cron or with the server checking/restarting script, and that does not run, either.

I have edited my crontab file in the usual way ("crontab -e" at the command line) to contain what I am fairly sure after triple checking is the correct syntax for cron jobs (*/1 * * * * echo "TESTING" >> /var/log/simutrans/test.log in addition to the real command in similar syntax). The /var/log/simutrans/test.log file is never created. The real command points to /var/log/simutrans/check.log, which is appended properly when I run the command (simctrl brit check >> /var/log/simutrans/check.log) manually, but not when it is left to run from crontab.

I have checked that crontab is running (service crontab status, service crontab restart) and indeed it is. When I re-open the crontab file by using crontab -e, I can see my commands all there correctly, but they never execute.

Any help in tracking down the problem would be much appreciated!
 
Old 01-22-2012, 06:15 PM   #2
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,434

Rep: Reputation: 110Reputation: 110
Maybe a permission problem. Cron often runs as a separate user, and stuff inside /var/log/ is likely to be owned by root. I recommend checking the permissions on /var/log/simutrans/check.log as well as all parent dirs.

Also note that many host providers won't let you run cron jobs every minute. Check your provider's policy.
 
Old 01-22-2012, 06:45 PM   #3
jamespetts
Member
 
Registered: Sep 2002
Location: UK
Distribution: Ubuntu 11.10
Posts: 121

Original Poster
Rep: Reputation: 16
Thank you for your reply.

Hmm - to what should I set the permissions on /var/log etc.? As to server policies - I get root SSH access; is it likely that cron jobs would be restricted in those circumstances (and, if so, by what means)?
 
Old 01-23-2012, 07:57 AM   #4
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 15.2
Posts: 1,339

Rep: Reputation: 260Reputation: 260Reputation: 260
Which editor do you use for crontab -e? I found by accident (as it wasn’t working too), that the crond on at least one of my machines needs a line feed at the end of the last line. This is there if you use vi, but not with joe.
 
Old 01-23-2012, 12:55 PM   #5
lucmove
Senior Member
 
Registered: Aug 2005
Location: Brazil
Distribution: Debian
Posts: 1,434

Rep: Reputation: 110Reputation: 110
Quote:
Originally Posted by jamespetts View Post
Hmm - to what should I set the permissions on /var/log etc.? As to server policies - I get root SSH access; is it likely that cron jobs would be restricted in those circumstances (and, if so, by what means)?
Changing the permissions on /var/log is not wise. I just think you should try directing the output of that cron job to another file, one that you're absolutely sure it's writable by the cron process. Then you will know if the cron job is really working or not.
 
Old 01-23-2012, 01:02 PM   #6
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
Did you setup the cron as root?
Try to use the whole PATH to all the commands and files, since cron has a limited PATH
The cron user should receive an email in case of problems BTW

Kind regards
 
Old 01-23-2012, 03:12 PM   #7
jamespetts
Member
 
Registered: Sep 2002
Location: UK
Distribution: Ubuntu 11.10
Posts: 121

Original Poster
Rep: Reputation: 16
Thank you for all your replies! I used nano for editing the crontab file - there is indeed a line feed at the end of the file. I was logged in as root when I ran crontab -e. How would I know what user runs cron such that I should know what permissions to set to ensure that it is able to run the task? The echo TEST command would not have been affected by using the full path, but I have edited the file to use the whole path in any event (it is trying to run a shell script located in root's home directory). Finally, as to e-mail, how does one configure cron such as to set the address to which alerts will be sent?
 
Old 01-23-2012, 03:16 PM   #8
repo
LQ 5k Club
 
Registered: May 2001
Location: Belgium
Distribution: Arch
Posts: 8,529

Rep: Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899Reputation: 899
As root type
Code:
mail
to see root's mail.

Kind regards
 
Old 01-23-2012, 03:34 PM   #9
jamespetts
Member
 
Registered: Sep 2002
Location: UK
Distribution: Ubuntu 11.10
Posts: 121

Original Poster
Rep: Reputation: 16
The cron job seems to have started working again, although I am not quite sure what I did to get it to work (perhaps using the full path). Oddly, the test job still does not work, but that is rather by the way now. Thank you all for your help!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron jobs not running henrybg Linux - Enterprise 10 01-28-2013 10:23 AM
[SOLVED] Cron jobs not running saldon Linux - Server 2 01-08-2010 10:01 AM
Cron jobs stopped running sysbox Linux - General 1 11-30-2009 03:18 PM
One user's cron jobs not running dcroxton Linux - Software 5 03-06-2006 03:33 PM
cron jobs not running scarr3d Linux - Software 7 05-25-2004 04:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:04 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration