码迷,mamicode.com
首页 > 其他好文 > 详细

清除系统日志

时间:2018-03-01 20:14:07      阅读:128      评论:0      收藏:0      [点我收藏+]

标签:error_log   body   ash   令行   null   目录   保存日志   清除   line   

#!/bin/bash

LOG_DIR=/var/log
ERROR_ROOT=86
ROOT_UID=0
LINES=50
ERROR_LOG=87
#判断执行脚本的用户是不是root管理员,不是则返回错误代码
if [ "$UID" -ne "$ROOT_UID" ];then
        echo "This script must be run as root"
        exit $ERROR_ROOT
fi

#判断命令行是否输入参数,没有输入参数,默认保存日志的最后50行
if [ -n "$1" ];then
        lines=$1
else
        lines=$LINES
fi

#进入到日志目录,进行相关的清空工作
cd $LOG_DIR
if [ `pwd` != "$LOG_DIR" ];then
        echo "Cannot change to the $LOG_DIR"
        exit $ERROR_LOG
fi

tail -$lines messages > mesg.temp
mv mesg.temp messages

cat /dev/null > wtmp
cat /dev/null > utmp
echo "Logs clened up"

清除系统日志

标签:error_log   body   ash   令行   null   目录   保存日志   清除   line   

原文地址:https://www.cnblogs.com/fuyuteng/p/8489290.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!