Why service (start|stop) can not be called from cron?

Hi,

When I googled, I came to know that I can not call the command
"service <service-name> start" from cron, insted I have to specify path to the service-name.

I wanted to know the reason.

Thanks,
Hansini

have you tried running it with the full path to the command "service?" when you are running things in cron, you do not have a full environment unless you source one. Things that work for a user will not work in cron as a result.

Also, it is a good practice to not use the "service" command in a script. Instead, you should use the init script itself such as:

/etc/init.d/somedaemon start

Thanks! Mark.

Yes I tried by specifying path to the init script in cron. I wanted to know why. Now I got the answer.

Maybe the service command can't found, try to use /sbin/service ..

If it works, you need to add PATH env variable in cron job.