[lug] Re: Monitoring file descriptors

Ben Whaley bwhaley at gmail.com
Mon Jul 28 20:05:53 MDT 2008


Thanks Dave, always open to improvements. I knew there was a more
efficient way to do it.

- Ben


On 7/28/08, David L. Anselmi <anselmi at anselmi.us> wrote:
> Ben Whaley wrote:
>> Folks,
>  > Just trying to get us back on topic ;) Can't we all just be friends?
>
> No!  We can't all just be friends!  Your script sucks!  All your base
> are belong to us!!!
> ;-)
>
> But seriously, I always like to take things like this apart and put them
> back together.  (So I can't debug them later[1].)  (It's nice to hear
> about solutions like this, so don't take my changes as criticism.
> Decide for yourself which you like better.)
>
>> if [ `cat /proc/sys/fs/file-nr | awk '{ diff=$3 - $1; print diff }'` -lt
>> 20000 ]; then echo "Low on file descriptors - `cat /proc/sys/fs/file-nr |
>> awk '{ diff=$3 - $1; print diff }'`" | mail -s "ftp1 file descriptors"
>> ben at atrust.com; fi
>
> diff=`awk '{ diff=$3 - $1; print diff }' /proc/sys/fs/file-nr` ;
> [ "$diff" -lt 2000 ] && echo "Low on file descriptors - $diff" |
>    mail -s "ftp1 file descriptors" ben at atrust.com
>
> (the line feeds are gratuitous).  It does the same thing with less awks
> and cats.  It seems worthwhile to save diff rather than recalculate it
> later.
>
> I'm always amused to see scripts at work that say:
>
> cat foo | grep bar | awk '{print $3}'
>
> which can be written as:
>
> awk '/bar/ {print $3}' foo
>
> (which, of course gets the foo and bar backwards so isn't nearly as
> aesthetic.) ;-)
>
> Dave
>
>   1.
> http://nedbatchelder.com/blog/200310/kernighan_on_debugging_clever_code.html
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug
> Join us on IRC: lug.boulder.co.us port=6667 channel=#colug
>

-- 
Sent from Gmail for mobile | mobile.google.com



More information about the LUG mailing list