[lug] Scripting question

Jeffrey S. Haemer jeffrey.haemer at gmail.com
Fri Dec 21 05:45:46 MST 2012


What Lee said.  Bash even lets me say it like this:

  cmd &>> /var/tmp/logfile.txt

but cron uses /bin/sh by default.

I've made enough "Heck. That's only in bash" mistakes in cron that I start
my crontabs as described here:

  http://seejeffrun.blogspot.com/search?q=crontab

which also says how I avoid losing cron's mail: I let Google store it for
me. :-)


On Thu, Dec 20, 2012 at 10:41 PM, Lee Woodworth <blug-mail at duboulder.com>wrote:

> 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
>
> _______________________________________________
> 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
>



-- 
Jeffrey Haemer <jeffrey.haemer at gmail.com>
720-837-8908 [cell], http://seejeffrun.blogspot.com [blog],
http://www.youtube.com/user/goyishekop [vlog]
*פרייהייט? דאס איז יאַנג דינען וואָרט.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20121221/cb5641c9/attachment.html>


More information about the LUG mailing list