cleanup:一个增强的和广义的删除 logfile 的脚本
2019-03-2113:34:15
记录linux shell 脚本言语的学过程。
同时也作为自己平时的积累。
1 #!/bin/sh 2 #set -x 3 LOG_DIR=/var/log 4 ROOT_UID=0 5 LINES=50 6 E_XCD=66 7 E_NOTROOT=67 8 9 if [ "$UID" -ne "$ROOT_UID" ] 10 then 11 echo; echo "You must be root to run this script."; echo 12 exit $E_NOTROOT 13 fi 14 15 if [ -n "$1" ] 16 then 17 lines=$1 18 else 19 lines=$LINES 20 fi 21 cd $LOG_DIR 22 if [ `pwd` != "$LOG_DIR" ] 23 then 24 echo "Can't change to $LOG_DIR." 25 exit $E_XCD 26 fi 27 tail -$lines message > mesg.temp 28 mv mesg.temp message 29 echo "Logs cleaned up." 30 exit
浙公网安备 33010602011771号