home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / cnews.tar / util / sfshproto < prev    next >
Text File  |  1995-04-27  |  2KB  |  60 lines

  1. #! /bin/sh
  2. # spacefor - determine available disk space
  3. # About how many things of $1 bytes will fit in the available space for
  4. # stuff of type $2 ("incoming", "articles", "control", "outbound $3",
  5. # "batchfiles", or "archive") without cramping things too badly?
  6. #
  7. # You'll have to change this -- your blocksize, minimum-free-desired amounts,
  8. # and df output format will probably differ, and you may need to name
  9. # your filesystems explicitly.  Note that all amounts are expressed in
  10. # target-filesystem blocks, not some arbitrary absolute unit.  (Absolute
  11. # units might be better but there is no agreement on what they should be.)
  12.  
  13. # =()<. ${NEWSCONFIG-@<NEWSCONFIG>@}>()=
  14. . ${NEWSCONFIG-/etc/news/bin/config}
  15.  
  16. PATH=$NEWSCTL/bin:$NEWSBIN:$NEWSPATH ; export PATH
  17. umask $NEWSUMASK
  18.  
  19. # head off special case
  20. case "$1" in
  21. 0)    echo 10000 ; exit 0 ;;
  22. esac
  23.  
  24. # argument to df, df units, and free space desired (in df units)
  25. dfunit=1024            # default df unit (bytes)
  26. case "$2" in
  27. incoming)    arg="$NEWSARTS/in.coming" ; desire=5000 ;;
  28. articles)    arg="$NEWSARTS" ; desire=5000 ;;
  29. control)    arg="$NEWSCTL" ; desire=3000 ;;        # for expire, mostly
  30. outbound)    arg="/var/spool/uucp" ; desire=10000 ;;    # ignore $3
  31. batchfiles)    arg="$NEWSARTS/out.going" ; desire=5000 ;;
  32. archive)    arg="$NEWSARTS" ; desire=1 ;;        # system-specific
  33. *)        arg="$2" ; desire = 1 ;;
  34. esac
  35.  
  36. # In the following, the initialization of nf determines which field the
  37. # block count comes from, and the one for nr determines which line.  For
  38. # System V, the Makefile edits in a sed which tries to strip silliness
  39. # off in a reasonably System-V-variant-independent way.  Expr would be
  40. # faster than awk, but on a 16-bit machine, expr does 16-bit arithmetic,
  41. # which isn't enough.
  42.  
  43. # this is set up for the stupid 4BSD df
  44. df $arg | awk "BEGIN { nf = 4 ; nr = 2 }
  45.     NR == nr && NF >= nf {
  46.         nb = (\$nf - $desire) * $dfunit / $1
  47.         if (nb > 10000)
  48.             nb = 10000    # ensure representable as integer
  49.         nb = int(nb)
  50.         if (nb <= 0)
  51.             print 0
  52.         else
  53.             print nb
  54.         exit
  55.     }
  56.     NR == nr && NF < nf {        # idiotic Berkeley continuation
  57.         nr += 1
  58.         nf -= 1
  59.     }"
  60.