#vi 1sh && chmod +x 1.sh
LOG_DIR=/var/log1
ROOT_UID=0
LINES=50
ERROR_CANTCD=112
ERROR_NOTROOT=765
if [ "$UID" -ne "$ROOT_UID" ]
then
echo "only root can run this script"
exit $ERROR_NOTROOT
if [ -n "$1" ]
then
lines=$1
else
lines=$LINES
fi
cd $LOG_DIR
if [ `pwd` != $LOG_DIR ]
then
echo "can not change to $LOG_DIR"
exit $ERROR_CANTCD
tail -$lines messages > mesg.tmp
mv mesg.tmp
echo "logs cleaned"
exit 0