Custom Search

System Log Rotation Script


#!/bin/sh
#written by brent kevin krkosska
#standard stuff, no surprises here
/etc/rc.d/init.d/sysklogd stop
chattr -a /var/log/*
mv /var/log/cron /var/log/cron.1
touch /var/log/cron
mv /var/log/lastlog /var/log/lastlog.1
touch /var/log/lastlog
mv /var/log/maillog /var/log/maillog.1
touch /var/log/maillog
mv /var/log/messages /var/log/messages.1
touch /var/log/messages
mv /var/log/secure /var/log/secure.1
touch /var/log/secure
mv /var/log/tty5 /var/log/tty5.1
touch /var/log/tty5
mv /var/log/wtmp /var/log/wtmp.1
touch /var/log/wtmp
mv /var/log/xferlog /var/log/xferlog.1
touch /var/log/xferlog
mv /var/log/local2 /var/log/local2.1
touch /var/log/local2
chmod go-rwx /var/log/*
chmod 644 /var/log/lastlog /var/log/wtmp
chattr +a /var/log/cron /var/log/faillog /var/log/maillog /var/log/messages
chattr +a /var/log/secure /var/log/sulog /var/log/tty5
chattr +a /var/log/xferlog /var/log/boot.log /var/log/btmp /var/log/wtmp
chattr +a /var/log/daemon.log /var/log/lastlog /var/log/user.log
/etc/rc.d/init.d/sysklogd start
for f in /var/log/*.1 ; do gzip -9 $f ; done









###########  Older Redhat log rotation:

# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

# send errors to root
errors root

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
#compress

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own lastlog or wtmp -- we'll rotate them here
/var/log/wtmp {
    monthly
    create 0664 root utmp
    rotate 1
}

# system-specific logs may be configured here

/var/log/pacct {
create
    postrotate
	/usr/bin/killall -HUP syslogd
chmod 600 /var/log/pacct
    endscript
}

/var/log/tty5 {
create
    postrotate
	/usr/bin/killall -HUP syslogd
chmod 600 /var/log/tty5
    endscript
}

/var/log/portsentry {
#missingok - for portsentry, missing is NOT ok!
create
    postrotate
	/usr/bin/killall -HUP syslogd
chmod 600 /var/log/portsentry
    endscript
}







www.fiveanddime.net








Custom Search