Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to run a service command via cron

Tags:

cron

service

service service_name start 

When i tried running this from cmd line, it works. But when i try to schedule it via cron, i get an error saying

/bin/sh: service: command not found

like image 857
Ash Avatar asked Nov 14 '11 20:11

Ash


People also ask

Why does my cron job not run?

Why is crontab not working in your system? Crontab might fail for a variety of reasons: The first reason is that your cron daemon might not be working for any reason, resulting in your crontab failing. There also exists a possibility that your system's environment variables are not settled correctly.

What is the use of * * * * * In cron?

It is a wildcard for every part of the cron schedule expression. So * * * * * means every minute of every hour of every day of every month and every day of the week .

Can cron run commands?

Cron allows Linux and Unix users to run commands or scripts at a given date and time. You can schedule scripts to be executed periodically. Cron is one of the most useful tool in a Linux or UNIX like operating systems. It is usually used for sysadmin jobs such as backups or cleaning /tmp/ directories and more.


1 Answers

sbin is not in the path when run via cron. Specify the full path to service. This is probably either /sbin/service or /usr/sbin/service. You can find the path on your system by running which service.

like image 107
Dark Falcon Avatar answered Oct 14 '22 23:10

Dark Falcon