Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-12-2010, 11:49 AM   #1
LQ Newbie
Registered: Jul 2010
Posts: 3

Rep: Reputation: 0
Question Cron job with privileged commands - redhat linux


I want to create a cron job which has a few commands (to restore generic iptables with minimum level security) that need sudo privileges. The file has the following commands :

/sbin/iptables-save > /home/user1/iptables_bkp.txt
/sbin/iptables-restore > /home/user1/original_iptables.txt
/sbin/service iptables save
/sbin/service iptables restart

I have scheduled this as the root's crontab. It does execute at every timeout, however the iptables_bkp.txt file is blank, and the original iptables file is not uploaded.

Is there something missing that should be done to make this work ?

Old 07-12-2010, 12:46 PM   #2
Senior Member
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 250Reputation: 250Reputation: 250
You say "the file" has the following commands. Is it a script ? If so, you need to make sure you have chmodded it 755, and it probably won't hurt to have a shebang line at the top. Then you call the script from the crontab.

/sbin/iptables-save > /home/user1/iptables_bkp.txt
/sbin/iptables-restore > /home/user1/original_iptables.txt
/sbin/service iptables save
/sbin/service iptables restart
save as
chmod 755
chown root:root

Last edited by smoker; 07-12-2010 at 12:47 PM.


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
remote desktop - privileged commands genese Linux - Desktop 2 01-12-2010 07:58 PM
[SOLVED] Not able to run cron job for non-privileged user in RHEL 5.3 mail4vijay Linux - General 3 11-24-2009 11:18 AM
linux cron job duplicate job question cpthk Linux - Newbie 4 09-11-2009 09:52 PM
cron job as a non-privileged user do not run chakkerz Linux - General 5 06-03-2008 09:28 PM
adding a perl script to cron.daily / cron.d to setup a cron job CrontabNewBIE Linux - Software 6 01-14-2008 09:16 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:04 PM.

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