Jeremy Henty wrote:
BLFS doesn't include any way to rotate the system logs in /var/log
(unless I've missed something).  Any recommended methods?

I use the attached script, I don't recall the origin. It used to be better, but I have worked on it.

Note: I exclude the redundant kernel messages in sys.log with:
*.*;auth,authpriv,kern.none -/var/log/sys.log

---
David Jensen

#!/bin/bash
# cleanup, version 2
# Run as root, of course.

LOG_DIR=/var/log
ROOT_UID=0     # Only users with $UID 0 have root privileges.
DEF_LINES=50   # Default number of lines saved.
KERN_LINES=300 # Kernel log number of lines saved.
E_XCD=66       # Cannot change directory?
E_NOTROOT=67   # Non-root exit error.

if [ "$UID" -ne "$ROOT_UID" ]
then
  echo "Must be root to run this script."
  exit $E_NOTROOT
fi

cd $LOG_DIR || {
  echo "Cannot change to necessary directory." >&2
  exit $E_XCD;
}

trunc_log () {
   tail -$1 $2 > mesg.temp            # Saves last section of message log file.
   mv mesg.temp $2                    # Becomes new log.
}

trunc_log $KERN_LINES kern.log       # Special case, more lines saved
for name in {sys,auth,daemon,user,scrollkeeper} ; do
   trunc_log $DEF_LINES $name.log
done

cat /dev/null > wtmp
cat /dev/null > btmp
cat /dev/null > lastlog

echo "Logs cleaned up."

exit 0

-- 
http://linuxfromscratch.org/mailman/listinfo/blfs-support
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page

Reply via email to