LinuxQuestions.org
Did you know LQ has a Linux Hardware Compatibility List?
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 02-26-2010, 05:39 AM   #1
resigned
LQ Newbie
 
Registered: Jul 2003
Posts: 11

Rep: Reputation: 0
Question crontab script execution - different behaviour user-cronfile <-> system-wide cronfile


Hello everybody.

I stumbled upon the following:

Script iptables_reset.sh

Code:
#!/bin/bash

IPTABLES="$(which iptables)"

$IPTABLES -P INPUT ACCEPT
$IPTABLES -P FORWARD ACCEPT
$IPTABLES -P OUTPUT ACCEPT
$IPTABLES -F
$IPTABLES -X

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

Code:
0 12 * * * root /root/iptables/iptables_reset.sh
But it won't work, if i edit roots user-cronfile by using crontab(1):
Code:
crontab -l
# m h  dom mon dow   command
0 12 * * * /root/iptables/iptables_reset.sh
The log entry is the same for system-wide and user-cronfile:
Code:
/USR/SBIN/CRON[5135]: (root) CMD (/root/iptables/iptables_reset.sh)
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?!
 
Old 02-26-2010, 06:01 PM   #2
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

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

Last edited by Berhanie; 02-26-2010 at 06:03 PM.
 
Old 02-28-2010, 11:24 PM   #3
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,289

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
Non-root user wouldn't have that in their path...
 
Old 03-01-2010, 10:35 AM   #4
Berhanie
Senior Member
 
Registered: Dec 2003
Location: phnom penh
Distribution: Fedora
Posts: 1,625

Rep: Reputation: 165Reputation: 165
the user is root .
 
Old 03-01-2010, 08:55 PM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,289

Rep: Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034Reputation: 2034
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: http://adminschoice.com/crontab-quic...Crontab%20file
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to start wireless system wide before a user logs in Skaperen Ubuntu 7 07-19-2009 03:05 AM
system wide read only user? bobinabottle Linux - Security 2 02-28-2009 07:23 AM
auto execution of script on ubuntu when user login Mr.J Ubuntu 2 07-04-2008 05:04 AM
script in crontab do not execute or take proper environment of user mayank_a Linux - Server 1 07-02-2007 05:03 AM
system-wide crontab in /etc/crontab ner Linux - General 2 11-18-2003 12:35 PM


All times are GMT -5. The time now is 06:54 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration