-   Linux - Software (
-   -   crontab script execution - different behaviour user-cronfile <-> system-wide cronfile (

resigned 02-26-2010 06:39 AM

crontab script execution - different behaviour user-cronfile <-> system-wide cronfile
Hello everybody.

I stumbled upon the following:




IPTABLES="$(which iptables)"


exit 0

This works if I edit the system-wide crontab in /etc/crontab like this:


0 12 * * * root /root/iptables/
But it won't work, if i edit roots user-cronfile by using crontab(1):

crontab -l
# m h  dom mon dow  command
0 12 * * * /root/iptables/

The log entry is the same for system-wide and user-cronfile:

/USR/SBIN/CRON[5135]: (root) CMD (/root/iptables/
I tried different things and found out, if i don't use the "$(which iptables)" substitution in the script, it also works with the user-cronfile.
What i can't figure out is why. Maybe someone can enlighten me?!

Berhanie 02-26-2010 07:01 PM

maybe the user cron doesn't have a correct PATH.
if so, you just have to define PATH somewhere (the script or the crontab).

chrism01 03-01-2010 12:24 AM

Non-root user wouldn't have that in their path...

Berhanie 03-01-2010 11:35 AM

the user is root ;).

chrism01 03-01-2010 09:55 PM

Really, the main point is that the default env settings for cron are minimal; this sort of issue, even for quite innocuous cmds/files is common.
The general rule is (search LQ) to always use full paths to all cmds/files required if running under cron.
Other options include sourcing the relevant user's .bash_profile/.bashrc files or set the cron env vars:

All times are GMT -5. The time now is 12:49 PM.