home *** CD-ROM | disk | FTP | other *** search
/ norge.freeshell.org (192.94.73.8) / 192.94.73.8.tar / 192.94.73.8 / pub / computers / 3b2 / spacewatch < prev    next >
Text File  |  1985-07-02  |  2KB  |  98 lines

  1. #    @(#)spacewatch    1.1    /sccs/src/cmd/sadmin/shell/s.spacewatch
  2. #    Look at file system space
  3.  
  4. #!    chmod +x ${file}
  5.  
  6. if [ $# -lt 1 ]
  7. then
  8.     echo >&2 "Usage:  $0 [ -w | -u ] [ -b<blocks> ] [ -i<inodes> ] file-system ...
  9. For more detail type:    prtdoc devcmd.$0"
  10.     exit 1
  11. fi
  12.  
  13. takenfs=
  14. blocks=500
  15. inodes=100
  16. output=stdout
  17.  
  18. dfout=`df  |  sed '    s/[ ():]\{1,\}/    /g
  19.             s/    blocks/ blocks/
  20.             s/    i-nodes/ i-nodes/'`
  21.  
  22. for i
  23. {
  24.     case ${i} in
  25.     -w )
  26.         output=wall
  27.         continue
  28.         ;;
  29.     -u )
  30.         output=users
  31.         continue
  32.         ;;
  33.     -b?* )
  34.         blocks=`expr ${i} : '..\(.*\)' \| ${blocks}`
  35.         continue
  36.         ;;
  37.     -i?* )
  38.         inodes=`expr ${i} : '..\(.*\)' \| ${inodes}`
  39.         continue
  40.         ;;
  41.     -* )
  42.         echo >&2 "$0:  illegal flag argument '${i}'"
  43.         exit 1
  44.         ;;
  45.     ALL )
  46.         #    all the remaining file systems take the last values
  47.         #    of ${blocks} and ${inodes}
  48.         list="${list}
  49.         "`echo "${dfout}"  |  cut -f1  |
  50.             fgrep -xv "${takenfs}"  |
  51.             sed "s;.*;\\$1 == \"&\"  \&\&  ( \\$3 <= ${blocks}  ||  \\$5 <= ${inodes} );"`
  52.         break
  53.     esac
  54.     list="${list}
  55.         \$1 == \"${i}\"  &&  ( \$3 <= ${blocks}  ||  \$5 <= ${inodes} )"
  56.     takenfs="${takenfs}
  57. ${i}"
  58. }
  59. if [ -z "${list}" ]
  60. then
  61.     exec $0
  62. fi
  63. out=`echo "${dfout}"  |  awk "${list}"`
  64. if [ -z "${out}" ]
  65. then
  66.     exit 0
  67. fi
  68.  
  69. case ${output} in
  70. wall )
  71.     echo "spacewatch:  These file systems low on space!\\n${out}"  |
  72.         /etc/wall
  73.     ;;
  74. users )
  75.     users=`who  |  cut -d' ' -f1`
  76.     msg=' is running out of room!  '
  77.     for fs in `echo "${out}"  |  cut -f1`
  78.     {
  79.         stats=`echo "${dfout}"  |  grep "^${fs}    "  |  cut -f3-`
  80.         case ${fs} in
  81.         /  |  /usr  |  /usr/*  |  /tmp  |  /tmp/* )
  82.             echo "spacewatch:  ${fs}${msg}${stats}"  |  /etc/wall
  83.             ;;
  84.         * )
  85.             for user in `cut -d: -f1,6 /etc/passwd  |
  86.                     grep ":${fs}/"  |  cut -d: -f1  |
  87.                     fgrep -x "${users}"`
  88.             {
  89.                 echo "spacewatch:  ${fs}${msg}${stats}"  |
  90.                     write ${user}
  91.             }
  92.         esac
  93.     }
  94.     ;;
  95. * )
  96.     echo "${out}"
  97. esac
  98.