home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / cmds / root.3 / usr / lib / acct / dodisk / dodisk~
Text File  |  1998-08-19  |  5KB  |  252 lines

  1. #!/sbin/sh
  2.  
  3. # Copyright (c) 1998 The Santa Cruz Operation, Inc.. All Rights Reserved. 
  4. #                                                                         
  5. #        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF THE               
  6. #                   SANTA CRUZ OPERATION INC.                             
  7. #                                                                         
  8. #   The copyright notice above does not evidence any actual or intended   
  9. #   publication of such source code.                                      
  10.  
  11. #    copyright    "%c%"
  12.  
  13. #ident    "@(#)acct:common/cmd/acct/dodisk.sh    1.13.2.8"
  14. #ident "$Header: $"
  15. # 'perform disk accounting'
  16. PATH=:/usr/lib/acct:/usr/bin:/usr/sbin
  17. export PATH
  18. _dir=/var/adm
  19. _pickup=acct/nite
  20.  
  21. set -- `getopt o $*`
  22. if [ $? -ne 0 ]
  23. then
  24.     echo "Usage: $0 [ -o ] [ filesystem ... ]"
  25.     exit 1
  26. fi
  27. for i in $*; do
  28.     case $i in
  29.     -o)    SLOW=1; shift;;
  30.     --)    shift; break;;
  31.     esac
  32. done
  33.  
  34. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  35. # Some systems may not use /etc/vfstab to store mount information #
  36. # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
  37. DEVLIST=/etc/vfstab
  38. format="special dev mnt fstype fsckpass automnt mntflags"
  39. if [ ! -f "$DEVLIST"  -a  "$SLOW" = "" ]
  40. then
  41.     echo "$DEVLIST does not exist: Use -o option"
  42.     echo "Usage: $0 [ -o ] [ filesystem ... ]"
  43.     exit 2
  44. fi
  45.  
  46. cd ${_dir}
  47.  
  48. if [ "$SLOW" = "" ]
  49. then
  50.     if [ $# -lt 1 ]
  51.     then
  52.     # Do disk accting for file systems in DEVLIST
  53.         while :
  54.         do
  55.             if read $format
  56.                    then
  57.                 if [ "$fsckpass" = "-" ]
  58.                 then
  59.                     continue
  60.                 fi
  61.                 if [ "$special" = "" ]
  62.                 then
  63.                     continue
  64.                 fi
  65.                 if [ "$special" = "-" ]
  66.                 then
  67.                     continue
  68.                 fi
  69.                 if [ "$dev" = "-" ]
  70.                 then
  71.                     continue
  72.                 fi
  73.                 if [ `expr $special : '\(.\)'` = \# ]
  74.                        then
  75.                                continue
  76.                     fi
  77.                 if [ "$fstype" = s5 ]
  78.                 then
  79.                     diskusg $dev > `basename $dev`.dtmp &
  80.                     continue
  81.                 fi
  82.                 if [ "$fstype" = bfs ]
  83.                 then
  84.                     bfsdiskusg $dev > `basename $dev`.dtmp &
  85.                     continue
  86.                 fi
  87.                 if [ "$fstype" = ufs ]
  88.                 then
  89.                     ufsdiskusg $dev > `basename $dev`.dtmp &
  90.                     continue
  91.                 fi
  92.                 if [ "$fstype" = sfs ]
  93.                 then
  94.                     sfsdiskusg $dev > `basename $dev`.dtmp &
  95.                     continue
  96.                 fi
  97.                 if [ "$fstype" = vxfs ]
  98.                 then
  99.                     vxdiskusg $dev > `basename $dev`.dtmp &
  100.                     continue
  101.                 fi
  102.                 # rfs and nfs fstypes not done 
  103.                 if [ "$fstype" = rfs ]
  104.                 then
  105.                     continue
  106.                 fi
  107.                 if [ "$fstype" = nfs ]
  108.                 then
  109.                     continue
  110.                 fi
  111.                 # fs is none of the above so use slow method
  112.                 if [ -d "$mnt" ]
  113.                 then
  114.                     find $mnt -print | acctdusg > `basename $dev`.dtmp &
  115.                 fi
  116.             else
  117.                 wait
  118.                 break
  119.             fi
  120.         done < $DEVLIST
  121.         ls *.dtmp >/dev/null 2>&1
  122.         if [ $? = 0 ]
  123.         then
  124.             cat *.dtmp | diskusg -s > dtmp
  125.             rm -f *.dtmp
  126.         else 
  127.             echo "dodisk: No appropriate filesystems"
  128.         fi
  129.     else
  130.     # do only those file systems in arg list
  131.         args="$*"
  132.         for i in $args; do
  133.             fstype=`fstyp $i`
  134.             # sort args by fstype
  135.             if [ "$fstype" = s5 ]
  136.             then
  137.                 s5="$s5 $i"
  138.                 continue
  139.             fi
  140.             if [ "$fstype" = bfs ]
  141.             then
  142.                 bfs="$bfs $i"
  143.                 continue
  144.             fi
  145.             if [ "$fstype" = sfs ]
  146.             then
  147.                 sfs="$sfs $i"
  148.                 continue
  149.             fi
  150.             if [ "$fstype" = ufs ]
  151.             then
  152.                 ufs="$ufs $i"
  153.                 continue
  154.             fi
  155.             if [ "$fstype" = vxfs ]
  156.             then
  157.                 vxfs="$vxfs $i"
  158.                 continue
  159.             fi
  160.             # don't do rfs and nfs
  161.             if [ "$fstype" = rfs ]
  162.             then
  163.                 continue
  164.             fi
  165.             if [ "$fstype" = nfs ]
  166.             then
  167.                 continue
  168.             fi
  169.             
  170.             # all other file system types are done via acctdusg
  171.             mnt=`df -n $i 2>/dev/null | cut -f 1 -d " "`
  172.             if [ -n "$mnt" ]
  173.             then
  174.                 other="$other $mnt"
  175.             else
  176.                 # df only gets mount name for /dev/dsk
  177.                 dirname=`dirname $i`
  178.                 if [ "$dirname" = "/dev/rdsk" ]
  179.                 then
  180.                     basename=`basename $i`
  181.                     mnt=`df -n "/dev/dsk/"${basename} 2>/dev/null | cut -f 1 -d " "`
  182.                 fi
  183.                 if [ -n "$mnt" ]
  184.                 then
  185.                     other="$other $mnt"
  186.                 else
  187.                     echo "dodisk: $i not done.  Bad name or not mounted."
  188.                 fi
  189.             fi
  190.         done
  191.         if [ -n "$s5" ]
  192.         then
  193.             diskusg $s5 > dtmp1 &
  194.         fi
  195.         if [ -n "$bfs" ]
  196.         then
  197.             bfsdiskusg $bfs > dtmp2 &
  198.         fi
  199.         if [ -n "$sfs" ]
  200.         then
  201.             sfsdiskusg $sfs > dtmp3 &
  202.         fi
  203.         if [ -n "$ufs" ]
  204.         then
  205.             ufsdiskusg $ufs > dtmp4 &
  206.         fi
  207.         if [ -n "$vxfs" ]
  208.         then
  209.             vxdiskusg $vxfs > dtmp5 &
  210.         fi
  211.         if [ -n "$other" ]
  212.         then
  213.             find $other -print | acctdusg > dtmp6 &
  214.         fi
  215.         wait
  216.         cat dtmp[1-6] | diskusg -s > dtmp
  217.         rm dtmp[1-6]
  218.     fi
  219. else
  220.     if [ $# -lt 1 ]
  221.     then
  222.         args="/"
  223.     else
  224.         args="$*"
  225.     fi
  226.     for i in $args; do
  227.         if [ ! -d $i ]
  228.         then
  229.             echo "$0: $i is not a directory -- ignored"
  230.         else
  231.             dir="$i $dir"
  232.         fi
  233.     done
  234.     if [ "$dir" = "" ]
  235.     then
  236.         echo "$0: No data"
  237.         > dtmp
  238.     else
  239.         find $dir -print | acctdusg > dtmp
  240.     fi
  241. fi
  242.  
  243. sort +0n +1 dtmp | acctdisk > ${_pickup}/disktacct 2>dodiskerr
  244. if [ -s dodiskerr ]
  245. then
  246.     cat dodiskerr > /dev/conslog
  247.     mail adm root <dodiskerr
  248.     rm -f dodiskerr
  249. fi
  250. chmod 644 ${_pickup}/disktacct
  251. chown adm ${_pickup}/disktacct
  252.