#! /bin/csh
#
# Perform part 1 of the system accounting.
# This command should be run on each node with accounting active.
#
# Version: 1995/05/04.
#
set host = `hostname`
set dir = //aurum/usr/local/lib/acct
#
# Should the accounting be done on this node?
#
if (-e /usr/adm/acct) then
   set file1 = $dir/acct.user.$host
   if (-e $file1) then
      echo "*** Error: file $file1 already exists."
      exit(1)
   endif
   echo "Writing user accounting into file $file1."
#  sa -ms >$file1
   sa -m /dev/null >$file1
   chmod 640 $file1
#
   set file2 = $dir/acct.process.$host
   if (-e $file2) then
      echo "*** Error: file $file2 already exists."
      exit(1)
   endif
   echo "No process accounting done for host $host."
#  echo "Writing process accounting into file $file2."
#  sa >$file2
#  sa /dev/null >$file2
#  chmod 640 $file2
else
#
# No accounting for this node.
#
   echo "No accounting done for node $host."
endif
#
# Do the Imagen print accounting on this node.
#
if (-f /usr/adm/imagen_acct/imagen && ! -z /usr/adm/imagen_acct/imagen) then
   set file3 = $dir/acct.imagen.$host
   if (-e $file3) then
      echo "*** Error: file $file3 already exists."
      exit(1)
   endif
   echo "Writing Imagen print accounting into file $file3."
   /usr/local/lib/imacct /usr/adm/imagen_acct/imagen | expand >$file3
   chmod 640 $file3
else
#
# No Imagen print accounting for this node.
#
   echo "No Imagen print accounting done for node $host."
endif
#
# Do the Phaser print accounting on this node.
#
if (-f /usr/adm/imagen_acct/phaser && ! -z /usr/adm/imagen_acct/phaser) then
   set file4 = $dir/acct.phaser.$host
   if (-e $file4) then
      echo "*** Error: file $file4 already exists."
      exit(1)
   endif
   echo "Writing Phaser print accounting into file $file4."
   cat /usr/adm/imagen_acct/phaser >$file4
   chmod 640 $file4
else
#
# No Phaser print accounting for this node.
#
   echo "No Phaser print accounting done for node $host."
endif
#
# Recreate the /usr/adm/wtmp file.
#
echo ""
echo "Cleaning up file /usr/adm/wtmp."
echo "*******************************"
echo ""
if (-e /usr/adm/wtmp) then
   rm /usr/adm/wtmp
   touch /usr/adm/wtmp
   chmod 666 /usr/adm/wtmp
   echo "/usr/adm/wtmp recreated."
else
   echo "/usr/adm/wtmp not found."
endif
#
# Move the /usr/adm/{critical,syslog} files to *.save.
#
echo ""
echo "Moving files /usr/adm/{Dailystuff.syslog,critical,syslog} to *.save."
echo "********************************************************************"
echo ""
if (-e /usr/adm/Dailystuff.syslog) then
   mv /usr/adm/Dailystuff.syslog{,.save}
   touch /usr/adm/Dailystuff.syslog
   chmod 640 /usr/adm/Dailystuff.syslog
   echo "System logging file /usr/adm/Dailystuff.syslog recreated."
else
   echo "File /usr/adm/Dailystuff.syslog not found - hope this is OK."
endif
if (-e /usr/adm/critical) then
   mv /usr/adm/critical{,.save}
   touch /usr/adm/critical
   chmod 644 /usr/adm/critical
   echo "System logging file /usr/adm/critical recreated."
else
   echo "File /usr/adm/critical not found - hope this is OK."
endif
if (-e /usr/adm/syslog) then
   mv /usr/adm/syslog{,.save}
   touch /usr/adm/syslog
   chmod 644 /usr/adm/syslog
   echo "System logging file /usr/adm/syslog recreated."
else
   echo "File /usr/adm/syslog not found - hope this is OK."
endif
#
# Move the /usr/spool/lpd/*/log files to *.save.
#
#echo ""
#echo "Moving files /usr/spool/lpd/*/log} to *.save."
#echo "*********************************************"
#echo ""
#foreach i (/usr/spool/lpd/*)
#   if (-e $i/log) then
#      mv $i/log{,.save}
#      touch $i/log
#      chown daemon $i/log
#      chmod 664 $i/log
#      echo "Print logging file $i/log recreated."
#   else
#      echo "File $i/log not found - hope this is OK."
#   endif
#end
#echo ""
#echo "Check '/usr/spool/lpd/*/log.save', then delete them."
#
# Move the /usr/adm/{sav,usr}acct files to *.save.
# Note that the clean-up of the accounting file is now done every day
# by the 'Dailystuff' script.
#
if (-e /usr/adm/acct) then
   echo ""
   echo "Moving files /usr/adm/{sav,usr}acct to *.save."
   echo "**********************************************"
   echo ""
#  mv /usr/adm/acct{,.save}
#  touch /usr/adm/acct
#  chmod 644 /usr/adm/acct{,.save}
#  /etc/accton /usr/adm/acct
#  echo "Accounting file /usr/adm/acct recreated and reactivated."
   if (-e /usr/adm/savacct) then
      mv /usr/adm/savacct{,.save}
      chmod 644 /usr/adm/savacct.save
   else
      echo "File /usr/adm/savacct not found - hope this is OK."
      echo ""
   endif
   if (-e /usr/adm/usracct) then
      mv /usr/adm/usracct{,.save}
      chmod 644 /usr/adm/usracct.save
   else
      echo "File /usr/adm/usracct not found - hope this is OK."
      echo ""
   endif
   echo "Check file $file1,"
   echo "then '/usr/adm/{sav,usr}acct.save' could be deleted."
endif
#
# Move the /usr/adm/imagen_acct/imagen file to *.save.
#
if (-f /usr/adm/imagen_acct/imagen && ! -z /usr/adm/imagen_acct/imagen) then
   echo ""
   echo "Moving file /usr/adm/imagen_acct/imagen to *.save."
   echo "**************************************************"
   echo ""
   mv /usr/adm/imagen_acct/imagen{,.save}
   touch /usr/adm/imagen_acct/imagen
   chown daemon.daemon /usr/adm/imagen_acct/imagen
   chmod 664 /usr/adm/imagen_acct/imagen
   echo "Imagen print accounting file /usr/adm/imagen_acct/imagen recreated."
   echo ""
   echo "Check file $file3,"
   echo "then '/usr/adm/imagen_acct/imagen.save' could be deleted."
endif
#
# Move the /usr/adm/imagen_acct/phaser file to *.save.
#
if (-f /usr/adm/imagen_acct/phaser && ! -z /usr/adm/imagen_acct/phaser) then
   echo ""
   echo "Moving file /usr/adm/imagen_acct/phaser to *.save."
   echo "**************************************************"
   echo ""
   mv /usr/adm/imagen_acct/phaser{,.save}
   touch /usr/adm/imagen_acct/phaser
   chown daemon.daemon /usr/adm/imagen_acct/phaser
   chmod 664 /usr/adm/imagen_acct/phaser
   echo "Phaser print accounting file /usr/adm/imagen_acct/phaser recreated."
   echo ""
   echo "Check file $file4,"
   echo "then '/usr/adm/imagen_acct/phaser.save' could be deleted."
endif
#
# Try to "kill -HUP [syslogd]".
#
echo ""
echo "Doing 'kill -HUP pid[syslogd]' to restart message logging."
echo ""
kill -HUP `cat /etc/syslog.pid`
sleep 5
kill -HUP `cat /etc/syslog.pid`
sleep 5
kill -HUP `cat /etc/syslog.pid`
exit(0)
