I have a python script running as a service on Ubuntu11.10. I need to stop the service and then restart it again every 6 hours. I wrote the cronjob and just to check its working, i am stopping and starting the service every 5 mins. Following is the line in my crontab:

*/5 * * * * stop server && start server

I have written the above line in root's crontab. But its not working at all. From CLI the root can stop and start the server absolutely fine. But on automating it using cron, it's not working. Any ideas what I am doing wrong?

Referred the following page for the cronjob syntax.

Referred this as well, but didnt worked for me.

  • even tried the following in crontab:--- */2 * * * * username stop server && start server – bugs99 Jun 18 '12 at 9:28
  • Use the full path for stop and start – Sirch Jun 18 '12 at 9:29
  • tried the following:-- */5 * * * * stop /etc/init/server.conf && start /etc/init/server.conf but didnt work. – bugs99 Jun 18 '12 at 9:44
  • I meant /sbin/stop and /sbin/start, but interesting that you are stopping and starting server.conf, usually you stop and start services through scripts. Is the script a long one, possible to paste it, or just the first few lines? If a cron script fails to run it should log, or send mail. Have you checked roots mail recently? – Sirch Jun 18 '12 at 9:49
  • ok, even /sbin/stop /etc/init/server.conf ....... didnt work. Will try writing those command in a shell script and will try t0 automate that instead. mailx is not installed on the system – bugs99 Jun 18 '12 at 10:00

Have you tried using the full path to the stop and start executables?

What do you see in /var/log/cron.log?

  • I am using the script as a service, thats why using start and stop names.You mean start /etc/init/server.conf is it?? I dont have /var/log/cron.log. Using the following command to see the cron logs:--- grep cron /var/log/syslog Here's the output:--- – bugs99 Jun 18 '12 at 9:31
  • Jun 18 14:55:29 server crontab[3637]: (root) BEGIN EDIT (root) Jun 18 14:55:31 server crontab[3637]: (root) END EDIT (root) Jun 18 14:57:07 server crontab[3660]: (root) BEGIN EDIT (root) Jun 18 14:57:26 server crontab[3660]: (root) REPLACE (root) Jun 18 14:57:26 server crontab[3660]: (root) END EDIT (root) Jun 18 14:58:01 server cron[1006]: (root) RELOAD (crontabs/root) – bugs99 Jun 18 '12 at 9:33
  • its working now, took your answer the opposite way, My apologies. So it was /sbin/stop server && /sbin/start server that did the job – bugs99 Jun 18 '12 at 10:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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