Last active
August 29, 2015 14:02
-
-
Save kunpengku/0e0b5b3e0f54d1bec398 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
LOG_DIR=/var/log | |
ROOT_UID=0 | |
LINES=50 | |
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 | |
# 另一种检测命令行的方法 | |
# E_WRONGAGES=65 | |
# | |
# case "$1" in | |
# "" ) lines=50;; | |
# *[!0-9]*) echo "Usage: `basename $0` file-to-cleanup"; exit $E_WRONGAGES;; | |
# * ) lines=$1;; | |
# esac | |
cd $LOG_DIR | |
if [ `pwd` != "$LOG_DIR" ] | |
then | |
echo "Can't change to $LOG_DIR" | |
exit $E_XCD | |
fi | |
#再次确认目录 | |
tail -$lines messages > mesg.temp | |
mv mesg.temp messages | |
#cat /dev/null > messages | |
cat /dev/null > wtmp | |
echo "Logs cleaned up." | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment