#!/bin/bash #cleanup from abs#3 LOG_DIR=/var/log ROOT_UID=0 #the one whose uid=0 has the root priv. LINES=50 #default lines E_XCD=66 #exit code if cannot access the folder E_NOTROOR=67 #exit code if not the root user #check if user is root if [ "$UID" -ne "$ROOT_UID" ] then echo "must be root to run this script." exit $E_NOTROOT fi #check if there is cmd arg. if [ -n "$1" ] then lines=$1 else lines=$LINES #default fi cd $LOG_DIR #to ensure if you are in the log dir. if [ "$PWD" != "$LOG_DIR" ] then echo "cannot change to $LOG_DIR." exit $E_XCD fi tail -$lines messages >mesg.temp #save the last few lines to tmp file mv mesg.temp messages #move tmp to mess file cat /dev/null >wtmp echo "Logs cleaned up." exit 0