How do I run a `/usr/sbin/` binary in cron?

4

As root I added used crontab -e to add my script. However the script uses a binary in /usr/sbin/ and I get an error about it not existing when the script runs from cron. How do I fix this?

user3109

Posted 2015-05-21T17:59:32.310

Reputation:

Answers

7

You should just use the full path for the binary.

So let’s say you wanted to use ipconfig in a cron job. Instead of your crontab having a command like this:

ipconfig

You would change that to be:

/usr/sbin/ipconfig

Remember: Shell paths just tell the system where to look for binaries/executables when you call them from the command line to make your life typing commands easier. Providing the full path for binaries/executables works 100% the same for script use.

JakeGould

Posted 2015-05-21T17:59:32.310

Reputation: 38 217

3

Probably not the cleanest approach, but

You can set PATH variable in crontab, put this as the first line of your crontab

# start of crontab file
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

# your cron entries below

Dan

Posted 2015-05-21T17:59:32.310

Reputation: 324