一个简单的清除系统日志和登录日志的shell 脚本

#!/bin/sh


#clean up system  logs


LOG_DIR=/var/log

ROOT_UID=0  # When $UID=0, session have a root permission

LINES=50    # default save lines

E_XCD=66

E_NOTROOT=67


if [ "$UID" -ne "$ROOT_UID" ]; then

 echo "Must be root to run this script"

 exit $E_NOTROOT

fi


if [  -n "$1" ]; then

 lines=$1

else

 lines=$LINES

fi



cd $LOG_DIR

if [ `pwd` != "$LOG_DIR" ]; then

 echo "Can't change to $LOG_DIR."

 exit $E_XCD

fi

# if

#  cd /var/log || {echo "Can't change to necessary directory." >2&

#  exit E_XCD;}



tail -$lines messages >mesg.tmp


mv mesg.tmp messages



# cat /dev/null > messages

cat /dev/null > wtmp


echo "Logs cleaned up..."


exit 0