JJD
JJD

Reputation: 412

run sh script to stop and restart nginx as root from crontab?

I need a script to run a bash script that stops nginx dows a bunch of other stuff and then starts nginx

the crontab looks like this

5 10 * * 0 sh ~/runnow/script.sh

and I edited the crontab well logged in as root.

the script runs fine however the lines for stop and start of nginx give the error service not found.

echo "Stopping Nginx"
service nginx-sp stop

gives

Stopping Nginx
/root/run/script.sh: 2: /root/run/script.sh: service: not found

if I manually run the script logged on as root it runs fine. my thought is that crontab is not being run as root but searching for that it seems if you exited your crontab when logged in as root with crontab -e it should be run as root. and it must be since I am using ~/run/script.sh to run the script and the real path is /root/run/script.sh

so... im lost....

Upvotes: 1

Views: 1808

Answers (1)

Yedidia
Yedidia

Reputation: 998

As cyrus pointed ... use which to find service path in this way:

which service

Then add full path in your script.

Upvotes: 3

Related Questions