How to tell cron to find paths to tools?
Is there a way to indicate to cron how/where to find (paths to) tools such as python
, nmap
, php
and so on?
I ask this because when I schedule a job using crontab -e
, I always need to specify the full path of python
, nmap
and whatever other tool I want to use.
This is from man 5 crontab
:
Several environment variables are set up automatically by the cron(8) daemon. SHELL is set to /bin/sh, and LOGNAME and HOME are set from the /etc/passwd line of the crontab's owner. PATH is set to "/usr/bin:/bin". HOME, SHELL, and PATH may be overridden by settings in the crontab; LOGNAME is the user that the job is running from, and may not be changed.
So, PATH
is set by cron to "/usr/bin:/bin"
. Now, to add more paths to the PATH
to be used by cron, just edit the crontab file (using crontab -e
command) and add, for example the following line somewhere at the beginning:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
See also this Q&A from StackOverflow: crontab PATH and USER.