0

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.

bugs99
  • 15
  • 1
  • 8
  • even tried the following in crontab:--- */2 * * * * username stop server && start server – bugs99 Jun 18 '12 at 09:28
  • Use the full path for `stop` and `start` – Sirch Jun 18 '12 at 09:29
  • tried the following:-- */5 * * * * stop /etc/init/server.conf && start /etc/init/server.conf but didnt work. – bugs99 Jun 18 '12 at 09: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 09: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
  • ...is cron running? – Sirch Jun 18 '12 at 10:02
  • `ps aux | grep cron` – Sirch Jun 18 '12 at 10:05
  • finally its working. the key was:---- /sbin/stop server && and /sbin/start server and not /sbin/stop /etc/init/server.conf....... Checked from command line ig /sbin/stop /etc/init/server.conf was working or not. It wasnt so changed the path just to service name. and its working absolutely fine. Thanks a lot for your help. – bugs99 Jun 18 '12 at 10:11

1 Answers1

2

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

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

Ladadadada
  • 26,337
  • 7
  • 59
  • 90
  • 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 09: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 09: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