Please see this


Contents

- INDEX
- HP-UX Index
- Solaris
- Linux Index
- Other Unix types
- General Unix
- Unix Networking
- Unix Scripts
- Unix databases

Associated Information

- Unix Scripts Tips

Useful Links

- Bash shell HOWTO
- Bourne Shell Man Page
- C Shell Guide
- Korn Shell Resources

logrotate.sh

#!/usr/bin/sh #Below are scripts that rotate logs in cron job (Note, I'm using 9.x, 10.x #may have different logs and/or commands names). # # Rotate the following logs (ascii format) # # NOTES: # 1. Only these logs need to be rotated, since other are not used # 2. /etc/*log are not rotated on boot # 3. All binary logs (/etc/*tmp) are not rotated at all # 4. /usr/sam/log/samlog may not to be rotated since SAM ensures # that its size is not greater than set in options # LOGS="/usr/adm/messages \ /var/adm/sw/swcopy.log \ /var/adm/sw/swagentd.log \ /var/adm/sw/swagent.log \ /var/adm/sw/swinstall.log \ /var/adm/sw/patch/PATCH.log \ /var/adm/sw/swmodify.log \ /var/adm/sw/swremove.log \ /var/adm/sw/swpackage.log \ /var/adm/sw/swconfig.log \ "logrotate.sh" 126 lines, 3144 characters /var/spool/lp/log \ /var/spool/sw/swagent.log \ /var/ppl/log \ /var/opt/sharedprint/errorlog.test \ /var/opt/dce/config/dce_config.log \ /var/opt/dce/rpc/rpcd.log \ /var/opt/dde/dde_error_log \ /var/opt/hppak/hppak_error_log \ /var/opt/perf/datafiles/logindx \ /var/opt/perf/datafiles/logglob \ /var/opt/perf/datafiles/logappl \ /var/opt/perf/datafiles/logproc \ /var/opt/perf/datafiles/logdev \ /var/sam/log/samlog \ /var/adsm/dsmsched.log \ /var/adsm/dsmerror.log " # If log has more lines than the following number, rotate it MAXLINES=2000 # When rotating leave the following number of lines in log LEAVELINES=10 # Maintain the following number of backup copies COPIES=3 for log in $LOGS do if [ -f $log ] then if /bin/expr `/bin/wc -l < $log` - $MAXLINES - $LEAVELINES \> 0 then i=$COPIES while [ "$i" != "1" ] do if [ -f $log.`/bin/expr $i - 1` ] then /bin/mv -f $log.`/bin/expr $i - 1` $log.$i fi i=`/bin/expr $i - 1` done length=`/bin/wc -l < $log` base=`/bin/basename $log` /usr/bin/head -n `/bin/expr $length - $LEAVELINES` $log > $log.1 /bin/mv -f $log /tmp/$base.$$ /bin/tail -n +`/bin/expr $length - $LEAVELINES + 1` /tmp/$base.$$ > $log /bin/rm -f /tmp/$base.$$ fi fi done # # Rotate cron log # LOG=/usr/lib/cron/log MAXLINES=2000 COPIES=3 if [ -f $LOG ] then if /bin/expr `/bin/wc -l < $LOG` - $MAXLINES \> 0 then i=$COPIES while [ "$i" != "1" ] do if [ -f $LOG.`/bin/expr $i - 1` ] then /bin/mv -f $LOG.`/bin/expr $i - 1` $LOG.$i fi i=`/bin/expr $i - 1` done /bin/cp -p $LOG $LOG.1 >$LOG fi fi # Other Maintance - remove old files find /some/directory/somewhere -type f -atime +44 -exec rm {} \; #### END OF SCRIPT

Copyright 2000 Intronet Computers Ltd
Email: Intronet Computers for enquiries