home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / unix / admin / 6203 < prev    next >
Encoding:
Internet Message Format  |  1992-11-15  |  3.0 KB

  1. Path: sparky!uunet!van-bc!twg!bill
  2. From: bill@twg.bc.ca (Bill Irwin)
  3. Newsgroups: comp.unix.admin
  4. Subject: Re: does anyone have a disk x% full capture program???
  5. Message-ID: <2790@twg.bc.ca>
  6. Date: 16 Nov 92 06:03:37 GMT
  7. References: <fish.721343514@news2.gsfc.nasa.gov>
  8. Reply-To: bill@twg.bc.ca (Bill Irwin)
  9. Organization: The Westrheim Group, Vancouver, B.C., Canada
  10. Lines: 69
  11.  
  12. fish@daacdev1.stx.com writes:
  13.  
  14. : i'm just looking for something that would occasionally run and
  15. : see if a disk was more than say 90% full it would notify me
  16. : instead of waiting for the 100% full kernel warnings.
  17.  
  18. :       thanx,
  19. :               fish
  20.  
  21. This is a shell script I whipped up one day when I got surprised
  22. about a filesystem running out of space.
  23.  
  24. ----------------- snip  8<  8<  8<  snip ------------
  25. Used=99         # Percent of file system used for warning.
  26. Blocks=5000     # Minimum free blocks
  27. Warning=no
  28. [ $# -gt 0 ] && MailTo=$1
  29. for Sizes in `df -v | grep -v Filesystem|awk '{print $6}'`
  30. do
  31.         if [ $Sizes -gt $Used ]
  32.         then Print=yes
  33.         fi
  34. done
  35. for Sizes in `df -v | grep -v Filesystem|awk '{print $5}'`
  36. do
  37.         if [ $Sizes -lt $Blocks ]
  38.         then Print=yes
  39.         fi
  40. done
  41. if [ ${Print=no} = yes ]
  42. then
  43.         case $MailTo in
  44.                 [A-z0-9]*)
  45.                         TempFile=/tmp/dl.$$
  46.                         echo "File System          % Used" >$TempFile
  47.                         echo "-----------          ------     ---------Free  Space--------\n"\
  48.                                 >>$TempFile
  49.                         df -v | grep -v Filesystem | \
  50.                         awk '{
  51.                                 if( $6 > '$Used' || '$Blocks' > $5 )
  52.                                 printf( "%-10s\t\t%s\t%6d blocks   %3d.%1d Mbytes\n", \
  53.                                 $2, $6, $5, $5 * 512 / 1000000, $5 * 512 % 1000000 / 100000 )\
  54.                         }' >> $TempFile
  55.                         mail -s "*** WARNING *** Disk Low" $MailTo <$TempFile
  56.                         rm $TempFile
  57.                         ;;
  58.                 *)
  59.                         echo "File System          % Used"
  60.                         echo "-----------          ------     ---------Free  Space--------\n"
  61.                         df -v | grep -v Filesystem | \
  62.                         awk '{
  63.                                 if( $6 > '$Used' || '$Blocks' > $5 )
  64.                                 printf( "%-10s\t\t%s\t%6d blocks   %3d.%1d Mbytes\n", \
  65.                                 $2, $6, $5, $5 * 512 / 1000000, $5 * 512 % 1000000 / 100000 )\
  66.                         }'
  67.                         ;;
  68.         esac
  69. else
  70.         echo "\nNo filesystems are low on space."
  71. fi
  72.  
  73. ----------------- snip  8<  8<  8<  snip ------------
  74.  
  75. Hope this helps.
  76. -- 
  77. Bill Irwin    -       The Westrheim Group     -    Vancouver, BC, Canada
  78. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  79. uunet!twg!bill            (604) 431-9600 (voice) |     Your Computer  
  80. bill@twg.bc.ca            (604) 430-4329 (fax)   |    Systems Partner
  81.