[lug] Scripting question

Lee Woodworth blug-mail at duboulder.com
Thu Dec 20 22:41:14 MST 2012


On 12/20/12 21:03, Jed S. Baer wrote:
> 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

Don't know if that will work, but this does work for me:

# cmd >>/var/tmp/logfile.txt 2>&1

The order of the redirections matters, the logic is approximately:
1) redirect fd 1 to /var/tmp/logfile.txt in append mode,
2) redirect fd 2 to a duplicate of fd 1 (thus inheriting the append mode).

Jeff H. probably knows the more rigorous description of what this does.

> 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.
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: irc.hackingsociety.org port=6667 channel=#hackingsociety




More information about the LUG mailing list