LinuxQuestions.org
Review your favorite Linux distribution.
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 09-03-2014, 06:04 PM   #1
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 231

Rep: Reputation: 5
Problem executing commandline from script via cron


I am having trouble executing the iptables list commandline below within a script. When I execute the script within the /etc/SSH404Block/ folder as ./SSH404Block.sh, the iptables list is placed correctly into the temp2b.txt file. If I try to execute the SSH404Block.sh with the Cronjob line below, the iptables list is missing and the file will be empty.

Any clues as to how to fix this? Thanks.

filePath=/etc/SSH404Block
iptables -L -n -v --line-numbers | sort -n -k9 > $filePath/temp2b.txt # get cur iptables


Cronjob:
*/5 * * * * /etc/SSH404Block/SSH404Block.sh
 
Old 09-03-2014, 07:23 PM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Hi,

the environment is pretty minimal for cron jobs, so setting the PATH to include /sbin/ or explicitly calling /sbin/iptables may be required.

HTH,

Evo2.
 
Old 09-03-2014, 10:40 PM   #3
solarisguy
Member
 
Registered: Aug 2010
Location: Seattle
Distribution: CentOS, RHEL, Oracle Enterprise Linux, Solaris, BSD
Posts: 64

Rep: Reputation: 17
^ He's correct.

One would accomplish this by including the following on the second line of the script:

Code:
export PATH=$PATH:/sbin
 
Old 09-04-2014, 11:14 AM   #4
battles
Member
 
Registered: Apr 2014
Distribution: Debian GNU/Linux 7.5 (wheezy)
Posts: 231

Original Poster
Rep: Reputation: 5
WOW! You are all life savers. I have been working on this all yesterday afternoon and this morning. The LQ system isn't sending me message notices for some reason so I didn't see your messages until I came back in to ask another question. I tried your suggestion and it worked. I would have never figured out this command - 'export PATH=$PATH:/sbin'.

Thanks much!
 
  


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
cron not executing a script KroniK Linux - Newbie 4 01-07-2014 09:26 PM
[SOLVED] cron in debian is not executing a script at the scheduled time educated__fool Linux - Newbie 8 09-20-2012 02:37 AM
Problem executing scripts from cron. glore2002 Debian 6 10-01-2009 11:40 AM
Bash script run via cron not executing MYSQL command mackstar Linux - Server 4 04-23-2009 06:01 AM
Cron not Executing PHP script Badnoodles Linux - General 2 10-25-2006 05:56 PM


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

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