3124 Remove any existing references to utmp, use utmpx instead
[unleashed.git] / usr / src / cmd / bnu / uudemon.cleanup
blobe49cb4a536f58d7d0168bc32b3f82f6c3526c1ea
1 #!/usr/bin/sh
3 # CDDL HEADER START
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License, Version 1.0 only
7 # (the "License"). You may not use this file except in compliance
8 # with the License.
10 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11 # or http://www.opensolaris.org/os/licensing.
12 # See the License for the specific language governing permissions
13 # and limitations under the License.
15 # When distributing Covered Code, include this CDDL HEADER in each
16 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17 # If applicable, add the following below this CDDL HEADER, with the
18 # fields enclosed by brackets "[]" replaced with your own identifying
19 # information: Portions Copyright [yyyy] [name of copyright owner]
21 # CDDL HEADER END
24 # Copyright 1997 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
27 #ident "%Z%%M% %I% %E% SMI"
29 # This demon cleans up uucp directories.
30 # It is started by /var/spool/cron/crontabs/uucp;
31 # it can be run daily, weekly, whatever depending on the system
32 # uucp load.
35 # return a list of systems defined in /etc/uucp/Systems
36 getsystems() {
37 if [ ! -f /etc/uucp/Systems ]; then
38 return
39 else
40 awk '$1 !~ /^#/ {print $1}' /etc/uucp/Systems
44 # return a list of systems defined in /etc/asppp.cf
45 getpppsystems() {
46 if [ ! -f /etc/asppp.cf ]; then
47 return
48 else
49 X=`sed -e 's/#.*$//' /etc/asppp.cf`
50 set -- $X
51 while [ $# -ne 0 ];
53 if [ "$1" = "peer_system_name" ]; then
54 PPPSYSTEMS="$PPPSYSTEMS $2"
56 shift
57 done
58 echo "$PPPSYSTEMS"
62 nouucp() {
63 # run through the systems list, deleting ppp systems
64 outstr=""
65 for i in `getsystems`
67 del=0
68 for j in `getpppsystems`
70 if [ "$j" = "$i" ]; then
71 del=1
73 done
74 if [ $del -ne 1 ]; then
75 outstr="$outstr $i"
77 done
79 # if any names are in $outstr, assume uucp is configured
81 if [ -n "$outstr" ]; then
82 return 1
83 else
84 return 0
88 # Start of actual processing. For energystar compatibility,
89 # we attempt to do as little I/O as possible, so first check
90 # to see if uucp is configured before doing all this work.
92 if nouucp; then
93 exit 0
96 MAILTO=uucp
97 MAILDIR=/var/mail
98 export PATH
99 PATH=/usr/bin:/usr/lib/uucp
100 TMP=/tmp/uu$$
102 # Running as uucp, take care to protect things
104 umask 0022
107 # These are taken from the Makefile. If changed in Makefile
108 # they must be changed here also.
110 PUBDIR=/var/spool/uucppublic
111 SPOOL=/var/spool/uucp
112 VAR=/var/uucp
113 LOCKS=/var/spool/locks # needs a comment in parms.h on USRSPOOLOCKS
114 XQTDIR=$VAR/.Xqtdir
115 CORRUPT=$SPOOL/.Corrupt
116 LOGDIR=$VAR/.Log
117 SEQDIR=$VAR/.Sequence
118 STATDIR=$VAR/.Status
119 WORKDIR=$SPOOL/.Workspace
120 ADMIN=$VAR/.Admin
122 # OLD is the directory for archiving old admin/log files
123 OLD=$VAR/.Old
124 O_LOGS=$OLD/Old-Log
125 ACCT_LOGS=$OLD/Old-acct
126 SEC_LOGS=$OLD/Old-sec
128 [ -f $ADMIN/xferstats ] && mv $ADMIN/xferstats $OLD/xferstats
129 [ -f $ADMIN/audit ] && mv $ADMIN/audit $OLD/audit
130 [ -f $ADMIN/command ] &&mv $ADMIN/command $OLD/command
131 [ -f $ADMIN/errors ] && mv $ADMIN/errors $OLD/errors
132 [ -f $ADMIN/Foreign ] && mv $ADMIN/Foreign $OLD/Foreign
134 > $ADMIN/xferstats
135 > $ADMIN/audit
136 > $ADMIN/command
137 > $ADMIN/errors
138 > $ADMIN/Foreign
141 # If performance log exists, save it and create a new one
143 if [ -f $ADMIN/perflog ]
144 then
145 mv $ADMIN/perflog $OLD/perflog
146 > $ADMIN/perflog
150 # The list in the for controls how many old Log and security logs
151 # are retained: 2 -> 3, 1 -> 2, current -> 1.
153 for i in 2 1
155 j=`expr $i + 1`
156 [ -f ${O_LOGS}-$i ] && mv ${O_LOGS}-$i ${O_LOGS}-$j
157 [ -f ${SEC_LOGS}-$i ] && mv ${SEC_LOGS}-$i ${SEC_LOGS}-$j
158 done
160 [ -f $ADMIN/security ] && mv $ADMIN/security ${SEC_LOGS}-1
161 > $ADMIN/security
164 # Combine all log files into O_LOGS-1.
165 # Add a name separator between each system.
167 > ${O_LOGS}-1
168 for i in uucico uucp uux uuxqt
170 if [ ! -d $LOGDIR/$i ]
171 then
172 (echo "uudemon.cleanup: $LOGDIR/$i directory does not exist, remove if file"
173 echo "uudemon.cleanup: making a directory $LOGDIR/$i"
174 ) | mail $MAILTO
175 rm -f $LOGDIR/$i
176 mkdir $LOGDIR/$i
177 continue
179 cd $LOGDIR/$i
181 # can't compare exactly because of symlinks
182 case `pwd` in
183 *`basename $LOGDIR`/$i)
186 (echo "uudemon.cleanup: unable to chdir to $LOGDIR/$i") | mail $MAILTO
187 continue
189 esac
190 for j in *
192 if [ "$j" = "*" ]
193 then
194 break
196 echo "********** $j ********** ($i)" >> ${O_LOGS}-1
197 cat $j >> ${O_LOGS}-1
198 rm -f $j
199 done
200 done
203 # If the accounting log exists, save it and create a new one.
204 # The list in the for controls how many old accounting logs
205 # are retained: 2 -> 3, 1 -> 2, current -> 1.
207 if [ -f $ADMIN/account ]
208 then
209 for i in 2 1
211 j=`expr $i + 1`
212 [ -f ${ACCT_LOGS}-$i ] && mv ${ACCT_LOGS}-$i ${ACCT_LOGS}-$j
213 done
214 [ -f $ADMIN/account ] && mv $ADMIN/account ${ACCT_LOGS}-1
215 > $ADMIN/account
218 # Execute the system directory cleanup program
219 # See uucleanup.1m for details.
220 uucleanup -D7 -C7 -X2 -o2 -W1
222 # Use the grep instead of the mv to ignore warnings to uucp
223 # grep -v 'warning message sent to uucp' $ADMIN/uucleanup > $OLD/uucleanup
224 [ -f $ADMIN/uucleanup ] && mv $ADMIN/uucleanup $OLD/uucleanup
225 if [ -s $OLD/uucleanup ]
226 then
227 (echo "Subject: cleanup"; echo; cat $OLD/uucleanup) | mail $MAILTO
229 >$ADMIN/uucleanup
231 # cleanup funny directories that may have been created in the spool areas
232 for d in $SPOOL/[0-9A-Za-z]*
234 if [ -f $d ]
235 then
236 # skip any regular files, like lockfiles
237 # and mail.log and so forth
238 continue
240 if [ -z "`ls $d`" ]
241 then
242 # empty directory
243 continue
245 cd $d
246 # we'd check that we were in the correct directory
247 if [ "`basename \`pwd\``" != "`basename $d`" ]
248 then
249 (echo "uudemon.cleanup: unable to chdir to $d") | mail $MAILTO
250 continue
252 for s in */*
254 if [ "$s" = "*/*" ]
255 then
256 break
258 if [ -d $s ]
259 then
260 # Remove subdirs of subdirs
261 rm -fr $s
263 done
265 # if it is now empty, remove it.
266 cd ..
267 rmdir $d/* $d
268 done >/dev/null 2>&1
271 # Find old cores
273 find $SPOOL -name core -print > $TMP
274 if [ -s $TMP ]
275 then
276 (echo "Subject: cores"; echo; cat $TMP) | mail $MAILTO
280 # Remove old files and directories
282 #find $PUBDIR -type f -mtime +30 -exec rm -f {} \;
283 find $PUBDIR/* -depth -type d -exec rmdir {} \; >/dev/null 2>&1
284 find $SPOOL/* -depth -type d -exec rmdir {} \; >/dev/null 2>&1
285 find $SEQDIR -type f -mtime +30 -exec rm -f {} \;
286 find $WORKDIR -type f -mtime +1 -exec rm -f {} \;
287 find $STATDIR -type f -mtime +2 -exec rm -f {} \;
288 find $CORRUPT -type f -mtime +10 -exec rm -f {} \;
290 rm -f $LOCKS/LTMP*
291 rmdir $SPOOL/[0-9A-Za-z]* >/dev/null 2>&1
294 # Mail a daily summary of status
296 grep passwd ${O_LOGS}-1 > $TMP
297 grep "REQUEST.*/" ${O_LOGS}-1 >> $TMP
298 if [ -s $TMP ]
299 then
300 (echo "Subject: uucp requests"; echo; cat $TMP) | mail $MAILTO
304 awk '/(DENIED)/ {print prev}
305 {prev = $0}' ${O_LOGS}-1 > $TMP
306 if [ -s $TMP ]
307 then
308 (echo "Subject: uucp DENIED"; echo; cat $TMP) | mail $MAILTO
311 uustat -q > $TMP
312 if [ -s $TMP ]
313 then
314 (echo "Subject: uu-status"; echo; cat $TMP) | mail $MAILTO
317 ls $CORRUPT > $TMP
318 if [ -s $TMP ]
319 then
320 (echo "Subject: $CORRUPT"; echo; cat $TMP) | mail $MAILTO
323 if [ -s $OLD/errors -o -s $OLD/Foreign ]
324 then
325 (echo "Subject: uucp Admin"; \
326 echo; echo tail errors; tail $OLD/errors; \
327 echo; echo tail Foreign; tail $OLD/Foreign; \
328 ) | mail $MAILTO
330 # don't run if no system directories exist
331 if [ "`echo $SPOOL/*`" != "$SPOOL/*" ]
332 then
333 (echo "Subject: uucleanup ran; $SPOOL du"; echo; du $SPOOL) | \
334 mail $MAILTO
338 # Dispose of mail to nuucp
340 rm -f $MAILDIR/nuucp $TMP