[lug] Scripting question

Jed S. Baer blug at jbaer.cotse.net
Thu Dec 20 21:03:07 MST 2012


On Fri, 21 Dec 2012 10:04:21 +0700
Paul Nowosielski wrote:

> Here is the commands I am running and the script I call:
> 
> /bin/date >> /root/scripts/bandwTest; /root/scripts/bandwidth.sh >> 
> /root/scripts/bandwTest;

As Davide pointed out, you're likely missing the PATH. Easiest thing to
do is invoke iptables as /sbin/iptables (or whatever the full path is).

Another question would be where is STDERR going? Off the top of
my head, I don't remember how cron handles that. Capturing it would
likely show you what's wrong. I often redirect it in the script itself,
but there are other ways to do it too. So my rendition of your script
would look like:

#!/bin/bash
exec >> /root/scripts/bandwTest 2>>&1
echo
echo "Bandwith out:"
/sbin/iptables -L -v |grep OUTPUT |awk '{print $7}'

However, I've never tried that using the concat style redirection, so I
don't know for sure it'll work. Usually, I do:

exec > foo.log 2>&1

And that's just from memory; consulting the exec manpage would be a good
thing.

And if you have no luck with this, might be good to see your crontab
entry.



More information about the LUG mailing list