[lug] Monitoring file descriptors

Jeffrey Haemer jeffrey.haemer at gmail.com
Mon Jul 28 19:58:18 MDT 2008


If only I had a mail program that interpreted "-E"  as "don't send if the
body's empty", this would be still easier for me to read.  (YMMV.)

   awk  '(diff = $3 - $1) < 10 {print "Low on file descriptors - " diff}'
/proc/sys/fs/file-nr |
     mail -E -s "ftp1 file descriptors" ben at atrust.com

Of course, that would require a Berkeley-style "mail" which would mean I
wouldn't have /proc.   Catch-22.

On Mon, Jul 28, 2008 at 6:56 PM, 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
>



-- 
Jeffrey Haemer <jeffrey.haemer at gmail.com>
720-837-8908 [cell]
http://goyishekop.blogspot.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lug.boulder.co.us/pipermail/lug/attachments/20080728/78aeef5d/attachment.html>


More information about the LUG mailing list