Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 4 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.