While they are similar, a user crontab (edited using crontab -e) is different from and keeps a separate path from the system crontab (edited by editing /etc/crontab).
The system crontab has 7 fields, inserting a username before the command. The user crontab, on the other hand, has only 6 fields, going directly into the command immediately after the time fields.
Likewise, the PATH in the system crontab normally includes the /sbin directories, whereas the PATH in the user crontab does not. If you want to set PATH for the user crontab, you need to define the PATH variable in the user crontab.
A simple workaround for adding your regular PATH in shell commands in cron is to have the cronjob source your profile by running bash in a login shell. for example instead of
* * * * * some command
You can instead run
* * * * * bash -lc some command
That way if your profile sets the PATH or other environment variables to something special, it also gets included in your command.
bash -lc
doesn't help. I'm good for now with setting PATH manually, but if I install some scripts, I want them to be recognized in cronjobs without specifying full paths. I'm sure it is possible somehow, andbash -lc
is on the way to a solution :) – csny Aug 03 '14 at 15:42~/.profile
and what do i have to add? – ttt Apr 29 '17 at 04:03