home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 15 / 15.iso / s / s053 / 11.ddi / usr / lib / uucp / uudemon.cleanup < prev    next >
Encoding:
Text File  |  1990-12-08  |  4.7 KB  |  225 lines

  1. #!/usr/bin/sh
  2. #ident    "@(#)/usr/lib/uucp/uudemon.cle.sl 1.1 4.0 12/08/90 43242 AT&T-USL"
  3. #
  4. #    This demon cleans up uucp directories.
  5. #    It is started by /var/spool/cron/crontabs/root;
  6. #    it can be run daily, weekly, whatever depending on the system
  7. #      uucp load.
  8. #    The log files get large so you may have to up the ulimit.
  9. #    e.g.
  10. #
  11. # 45 23 * * * ulimit 5000; /usr/bin/su uucp -c "/usr/lib/uucp/uudemon.cleanup"
  12. #
  13.  
  14. MAILTO=uucp
  15. MAILDIR=/var/mail
  16. export PATH
  17. PATH=/usr/bin:/usr/lib/uucp
  18. TMP=/tmp/uu$$
  19.  
  20. #    Running as uucp, take care to protect things
  21.  
  22. umask 0022
  23.  
  24. #
  25. #    These are taken from the Makefile.  If changed in Makefile
  26. #    they must be changed here also.
  27. #
  28. PUBDIR=/var/spool/uucppublic
  29. SPOOL=/var/spool/uucp
  30. VAR=/var/uucp
  31. LOCKS=/var/spool/locks    # needs a comment in parms.h on USRSPOOLOCKS
  32. XQTDIR=$VAR/.Xqtdir
  33. CORRUPT=$VAR/.Corrupt
  34. LOGDIR=$VAR/.Log
  35. SEQDIR=$VAR/.Sequence
  36. STATDIR=$VAR/.Status
  37. WORKDIR=$VAR/.Workspace
  38. ADMIN=$VAR/.Admin
  39.  
  40. #    OLD is the directory for archiving old admin/log files
  41. OLD=$VAR/.Old
  42. O_LOGS=$OLD/Old-Log
  43. ACCT_LOGS=$OLD/Old-acct
  44. SEC_LOGS=$OLD/Old-sec
  45.  
  46. mv $ADMIN/xferstats $OLD/xferstats
  47. mv $ADMIN/audit $OLD/audit
  48. mv $ADMIN/command $OLD/command
  49. mv $ADMIN/errors $OLD/errors
  50. mv $ADMIN/Foreign $OLD/Foreign
  51.  
  52. > $ADMIN/xferstats
  53. > $ADMIN/audit
  54. > $ADMIN/command
  55. > $ADMIN/errors
  56. > $ADMIN/Foreign
  57.  
  58. #
  59. #    If performance log exists, save it and create a new one
  60. #
  61. if [ -f $ADMIN/perflog ]
  62. then
  63.     mv $ADMIN/perflog $OLD/perflog
  64.     > $ADMIN/perflog
  65. fi
  66.  
  67. #
  68. #    The list in the for controls how many old Log and security logs
  69. #    are retained: 2 -> 3, 1 -> 2, current -> 1.
  70. #
  71. for i in  2 1
  72. do
  73.     j=`expr $i + 1`
  74.     mv ${O_LOGS}-$i ${O_LOGS}-$j
  75.     mv ${SEC_LOGS}-$i ${SEC_LOGS}-$j
  76. done
  77.  
  78. mv $ADMIN/security ${SEC_LOGS}-1
  79. > $ADMIN/security
  80.  
  81. #
  82. #    Combine all log files into O_LOGS-1.
  83. #    Add a name separator between each system.
  84. #
  85. > ${O_LOGS}-1
  86. for i in uucico uucp uux uuxqt
  87. do
  88.     if [ ! -d $LOGDIR/$i ]
  89.     then
  90.           (echo "uudemon.cleanup: $LOGDIR/$i directory does not exist, remove if file"
  91.            echo "uudemon.cleanup: making a directory $LOGDIR/$i"
  92.           ) | mail $MAILTO
  93.         rm -f $LOGDIR/$i
  94.         mkdir $LOGDIR/$i
  95.         continue
  96.     fi
  97.     cd $LOGDIR/$i
  98.     if [ "`pwd`" != "$LOGDIR/$i" ]
  99.     then
  100.           (echo "uudemon.cleanup: unable to chdir to $LOGDIR/$i") | mail $MAILTO
  101.         continue
  102.     fi
  103.     for j in *
  104.     do
  105.         if [ "$j" = "*" ]
  106.         then
  107.             break
  108.         fi
  109.         echo "********** $j ********** ($i)" >> ${O_LOGS}-1
  110.         cat $j >> ${O_LOGS}-1
  111.         rm -f $j
  112.     done
  113. done
  114.  
  115. #
  116. #    If the accounting log exists, save it and create a new one.
  117. #    The list in the for controls how many old accounting logs
  118. #    are retained: 2 -> 3, 1 -> 2, current -> 1.
  119. #
  120. if [ -f $ADMIN/account ]
  121. then
  122.     for i in  2 1
  123.     do
  124.         j=`expr $i + 1`
  125.         mv ${ACCT_LOGS}-$i ${ACCT_LOGS}-$j
  126.     done
  127.     mv $ADMIN/account ${ACCT_LOGS}-1
  128.     > $ADMIN/account
  129. fi
  130.  
  131. #    Execute the system directory cleanup program
  132. #    See uucleanup.1m for details.
  133. uucleanup -D7 -C7 -X2 -o2 -W1
  134.  
  135. #    Use the grep instead of the mv to ignore warnings to uucp
  136. # grep -v 'warning message sent to uucp' $ADMIN/uucleanup > $OLD/uucleanup
  137. mv $ADMIN/uucleanup $OLD/uucleanup
  138. if [ -s $OLD/uucleanup ]
  139. then
  140.     (echo "Subject: cleanup"; cat $OLD/uucleanup) | mail $MAILTO
  141. fi
  142. >$ADMIN/uucleanup
  143.  
  144. #  cleanup funny directories that may have been created in the spool areas
  145. cd $SPOOL
  146. #  check that we are in the correct directory
  147. if [ "`pwd`" != "$SPOOL" ]
  148. then
  149.     (echo "uudemon.cleanup: unable to chdir to $SPOOL") | mail $MAILTO
  150.     continue
  151. else
  152.     for d in $SPOOL/*/*/*
  153.     do
  154.     if [ "$d" != "$SPOOL/*/*/*" -a -d "$d" ]
  155.     then
  156.         rm -fr $d
  157.     fi
  158.     done
  159. fi
  160.  
  161. #
  162. #    Find old cores
  163. #
  164. find $SPOOL -name core -print > $TMP
  165. if [ -s $TMP ]
  166. then
  167.     (echo "Subject: cores"; cat $TMP) | mail $MAILTO
  168. fi
  169.  
  170. #
  171. #    Remove old files and directories
  172. #
  173. find $PUBDIR -type f -mtime +30 -exec rm -f {} \;
  174. find $PUBDIR/* -depth -type d -exec rmdir {} \;
  175. find $SPOOL/* -depth -type d -exec rmdir {} \;
  176. find $SEQDIR -mtime +30 -exec rm -f {} \;
  177. find $WORKDIR -mtime +1 -exec rm -f {} \;
  178. find $STATDIR -mtime +2 -exec rm -f {} \;
  179. find $CORRUPT -mtime +10 -exec rm -f {} \;
  180.  
  181. rm -f $LOCKS/LTMP*
  182.  
  183. #
  184. #    Mail a daily summary of status
  185. #
  186. grep passwd ${O_LOGS}-1 > $TMP
  187. grep "REQUEST.*/" ${O_LOGS}-1 >> $TMP
  188. if [ -s $TMP ]
  189. then
  190.     (echo "Subject: uucp requests"; cat $TMP) | mail $MAILTO
  191. fi
  192.  
  193.  
  194. awk '/(DENIED)/    {print prev}
  195.         {prev = $0}' ${O_LOGS}-1 > $TMP
  196. if [ -s $TMP ]
  197. then
  198.     (echo "Subject: uucp DENIED"; cat $TMP) | mail $MAILTO
  199. fi
  200.  
  201. uustat -q > $TMP
  202. if [ -s $TMP ]
  203. then
  204.     (echo "Subject: uu-status"; cat $TMP) | mail $MAILTO
  205. fi
  206.  
  207. ls $CORRUPT > $TMP
  208. if [ -s $TMP ]
  209. then
  210.     (echo "Subject: $CORRUPT"; cat $TMP) | mail $MAILTO
  211. fi
  212.  
  213. tail $OLD/errors 2>/dev/null > $TMP
  214. tail $OLD/Foreign 2>/dev/null >> $TMP
  215. if [ -s $TMP ]
  216. then
  217.     (echo "Subject: uucp Admin"; cat $TMP) | mail $MAILTO
  218. fi
  219. (echo "Subject: uucleanup ran; $SPOOL du"; du $SPOOL) | mail $MAILTO
  220.  
  221. #
  222. #    Dispose of mail to nuucp
  223. #
  224. rm -f $MAILDIR/nuucp $TMP
  225.