#! /bin/csh

# daily: daily system maintenance

set path = ( /bin /usr/bin /usr/lib /usr/contrib/bin /usr/local/bin /etc /usr/local/etc)
set nonomatch
set tmp = /tmp/daily.$$
umask 022
unset noclobber

##### fix mode and ownership of device files #####

# chmod 600  /dev/tnc*
# chmod 666            /dev/tty* /dev/pty/* /dev/ptym/*
# chown root /dev/tnc* /dev/tty* /dev/pty/* /dev/ptym/*
# chgrp root /dev/tnc* /dev/tty* /dev/pty/* /dev/ptym/*

##### remove garbage files #####

touch /usr/spool/mqueue/syslog

find /                 -name core        -exec rm -f {} \; >& /dev/null
find /                 -name dead.letter -exec rm -f {} \; >& /dev/null
find /tmp /usr/tmp     -atime +2         -exec rm -f {} \; >& /dev/null
find /usr/preserve     -atime +6         -exec rm -f {} \; >& /dev/null
## find /usr/spool/mqueue -mtime +6         -exec rm -f {} \; >& /dev/null

##### remove/truncate system logfiles #####

# rm -f                         /usr/lib/cron/OLDlog
# rm -f                         /usr/spool/lp/oldlog
trunc -b  0 -c 644 -m root /usr/adm/sulog
# trunc -b  5000 -c 644         /etc/backuplog
trunc -b  5000 -c 644         /usr/adm/messages
# trunc -b  1000 -c 644         /usr/spool/smail/log/logfile
trunc -b  1000 -c 644         /usr/lib/news/nntplog
# trunc -b  5000 -c 644         /usr/spool/lp/log*
trunc -b 50000 -c 644         /usr/spool/mqueue/syslog
trunc -b 0        -m root /usr/adm/OLDsulog

##### cleanup users #####

# udbm
# rmoldusers > /dev/null

##### cleanup net system #####

trunc -b 20000 -c 644 /tcp/net.log

find /tcp/logs      -mtime +6 -exec rm -f {} \; >& /dev/null

cd /tcp/util
# tar -tvfx util.tar
cp /users/src/convers/conversd /tcp/conversd
chmod og-rwx /tcp/conversd /tcp/util
##### Make /tcp backup     #####

cd /tcp
mv /users/src/tcpbak.tar.Z /users/src/otcpbak.tar.Z
tar -cvf /users/src/tcpbak.tar Makefile hosts convers* *.conf *.rc net* *data users src >/dev/null
compress /users/src/tcpbak.tar
ls -l /users/src/tcpbak.tar.Z
cd /users/src
doserase b:tcpbak.taz
dosput tcpbak.tar.Z b:tcpbak.taz

##### update lan databases #####

rm -rf /usr/spool/rwho/*

##### update mail databases #####

##### do an archive backup #####

# cd /
# touch /etc/archivedate
# ( echo "s `date` `uname -r` archive" ; \
#   find * -print | grep -v '^titus/' | cpio -oacx | compress | tcio -ov /dev/rct/c0 ; \
#   tcio -urV /dev/rct/c0 ; \
#   echo "f `date`" ; \
#   echo '-----' \
# ) >>& /etc/backuplog

##### the following is done only once in a week #####

# if (`date +%w` == 6) then

##### inform users about old files #####

# cd /users/funk
# foreach user (*)
  # find /users/funk/$user -atime +100 -print >$tmp
  # if ( ! -z $tmp ) then
    # echo '\nThese files were not accessed in the last 30 days.' >>$tmp
##  mailx -s 'Unused files' $user <$tmp
# mailx -s 'Unused files' olaf <$tmp
  # endif
# end
# rm -f $tmp

# endif
#
