3

On my Ubuntu 11.04 server when I try to run

 service powernap stop

as a cron job with the root user, it fails and gives me this message in syslog

 NAS CRON[10853]: (CRON) error (grandchild #10854 failed with exit status 2)

and this is emailed to the root users email account

 exec: 129: stop: not found

I can start and stop the powernap service from the command line so why doesn't it work from cron?

enzotib
  • 92,255
  • 11
  • 164
  • 178
Luke Stapley
  • 53
  • 1
  • 5

3 Answers3

4

Looks like /sbin is not in $PATH when starting it from cron. Add a line like

PATH = /sbin:$PATH

to the crontab file.

Florian Diesch
  • 86,013
  • 17
  • 224
  • 214
2

Hmmm...it's strange that cron is trying to run "stop"...

Try making cron run this instead:

sh -c '/usr/sbin/service powernap stop'
Andrew Gunnerson
  • 4,378
  • 4
  • 26
  • 22
2

I've had exactly this issue, and it would appear that the $PATH variable is completely empty when crontab is run, so it's not enough to put PATH=/usr/sbin;$PATH at the top of the crontab list.

So, what I did was (since I'm running this crontab as root, so I can turn off the squid proxy):

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/X11R6/bin

and it seems to have worked.

N.N.
  • 17,939
  • 18
  • 57
  • 92
james
  • 21
  • 1