LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Problem executing commandline from script via cron (https://www.linuxquestions.org/questions/linux-newbie-8/problem-executing-commandline-from-script-via-cron-4175517307/)

battles 09-03-2014 05:04 PM

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

evo2 09-03-2014 06:23 PM

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.

solarisguy 09-03-2014 09:40 PM

^ He's correct.

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

Code:

export PATH=$PATH:/sbin

battles 09-04-2014 10:14 AM

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!


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