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 / agefile < prev    next >
Text File  |  1985-05-23  |  2KB  |  130 lines

  1. #    @(#)agefile    1.2    /sccs/src/cmd/sadmin/shell/s.agefile
  2. #    age files by moving to older and older names (agefile)
  3.  
  4. #!    chmod +x ${file}
  5.  
  6. cmd=$0
  7. defaultcycles=4
  8. header=
  9. pack=    
  10.  
  11. set -- `getopt c:fhp $*` || exec ${cmd}
  12.  
  13. while [ -n "$1" ]
  14. do
  15.     case $1 in
  16.     -c )
  17.         shift
  18.         defaultcycles=$1
  19.         shift
  20.         ;;
  21.     -f )    # Take arguments from file name.
  22.         # Lines that start with  #  are comments.
  23.         shift
  24.         shift    #  get rid of -- introduced by getopt
  25.         cat $*  |  grep -v '^#'  |
  26.             xargs ${cmd} -c${defaultcycles} ${headflag} ${packflag} --
  27.         exit
  28.         ;;
  29.     -h )
  30.         header=all
  31.         headflag=$1
  32.         shift
  33.         ;;
  34.     -p )
  35.         pack=all
  36.         packflag=$1
  37.         shift
  38.         ;;
  39.     -- )
  40.         shift
  41.         break
  42.     esac
  43. done
  44.  
  45. if [ $# = 0 ]
  46. then
  47.     echo >&2 "Usage:  ${cmd} [ -c <cycles> ] [ -p ] [ -h ] file ...
  48.     ${cmd} [ -c <cycles> ] [ -p ] [ -h ] -f file ..."
  49.     exit 1
  50. fi
  51.  
  52. umask 000
  53. for file
  54. do
  55.     if [ -n "${headflag}" ]
  56.     then
  57.         header=yes
  58.     fi
  59.     if [ -n "${packflag}" ]
  60.     then
  61.         pack=.z
  62.     fi
  63.     case ${file} in
  64.     -c[0-9]* )
  65.         nextcycle=`expr ${file} : '-c\(.*\)'`
  66.         continue
  67.         ;;
  68.     -p )
  69.         pack=.z
  70.         continue
  71.         ;;
  72.     -h )
  73.         header=yes
  74.         continue
  75.     esac
  76.     if [ -n "${nextcycle}" ]
  77.     then
  78.         cycles=${nextcycle}
  79.         lastcycle=${nextcycle}
  80.         nextcycle=
  81.     else
  82.         cycles=${defaultcycles}
  83.         lastcycle=${defaultcycles}
  84.     fi
  85.  
  86.     if [ ! -f ${file} ]
  87.     then
  88.         echo >&2 "${cmd}:  No file '${file}'"
  89.         continue
  90.     fi
  91.  
  92.     basename=`basename ${file}`
  93.     while [ ${cycles} -gt 1 ]
  94.     do
  95.         prev=`expr ${cycles} - 1`
  96.         if [ `expr ${basename}-${cycles}${pack} : '.*'` -gt 14 ]
  97.         then
  98.             echo >&2 "${cmd}:  filename too long '${file}-${cycles}${pack}'"
  99.             cycles=${prev}
  100.             continue
  101.         fi
  102.         if [ ${cycles} = ${lastcycle} ]
  103.         then
  104.             rm -f ${file}-${cycles} ${file}-${cycles}.z
  105.         fi
  106.         if [ -f ${file}-${prev}.z ]
  107.         then
  108.             mv -f ${file}-${prev}.z ${file}-${cycles}.z
  109.         elif [ -f ${file}-${prev} ]
  110.         then
  111.             mv -f ${file}-${prev} ${file}-${cycles}
  112.         fi
  113.         cycles=${prev}
  114.     done
  115.     mv -f ${file} ${file}-1
  116.  
  117.     if [ -n "${pack}" ]
  118.     then
  119.         pack ${file}-1 >/dev/null 2>&1
  120.         pack=
  121.     fi
  122.  
  123.     >> ${file}
  124.     if [ ${header} ]
  125.     then
  126.         (date; echo ============================) >> ${file}
  127.         header=
  128.     fi
  129. done
  130.