Visit Jeremy's Blog.
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 09-03-2014, 05:04 PM   #1
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 ./, the iptables list is placed correctly into the temp2b.txt file. If I try to execute the 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.

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

*/5 * * * * /etc/SSH404Block/
Old 09-03-2014, 06:23 PM   #2
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

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


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

Rep: Reputation: 19
^ He's correct.

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

export PATH=$PATH:/sbin
Old 09-04-2014, 10:14 AM   #4
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!


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

All times are GMT -5. The time now is 01:09 AM.

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