LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

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


Hi,

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 ?

Regards,
~Abhi
 
Old 07-12-2010, 11:46 AM   #2
smoker
Senior Member
 
Registered: Oct 2004
Distribution: Fedora Core 4, 12, 13, 14, 15, 17
Posts: 2,279

Rep: Reputation: 249Reputation: 249Reputation: 249
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.

Code:
#!/bin/bash
/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 my_script.sh
chmod 755 my_script.sh
chown root:root my_script.sh

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


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


All times are GMT -5. The time now is 03:32 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration