首页 > 代码库 > 清理messages日志脚本

清理messages日志脚本

要求:

  • 清楚/var/log下messages日志文件的简单命令脚本

  • 要使用root身份来运行这个脚本

  • 清楚日志脚本,版本

#!/bin/bash
#清除日志脚本,版本2
LOG_DIR=/var/log
ROOT_UID=0     #$UID为0的时候,用户才具有root用户的权限
#要使用root用户运行
if ["$UID" -ne "$ROOT_UID"]
then
	echo "Must be root to run this script"
	exit 1
fi
cd $LOG_DIR || {                                  
	echo "cannot change to necessary directory" >&2     # || :是或的意思,如果前面执行不成功则会执行后面的  &2:标准错误
	exit 1
}
cat /dev/null > messages && echo "Logs cleaned up"      #清空日志
exit 0


本文出自 “小菜鸟” 博客,请务必保留此出处http://baishuchao.blog.51cto.com/12918589/1937247

清理messages日志脚本