Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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!
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.
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)?
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.
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.
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
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?
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!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.