Author:Bruce
#!/bin/bash
# Des:clear system log
# Author:Bruce
LOG_DIR=/var/log
ROOT_UID=0
######判断是否为root用户
if [ "$UID" -ne "$ROOT_UID" ]
then
echo "only root can run this script"
exit 1
fi
#####判断切换目录是否成功
cd $LOG_DIR || {
echo "failed to change directory"
exit 1
}
cat /dev/null > messages && {
echo "logs clean up successfully"
exit 0
}
echo "Logs cleanup failed"
exit 1
调试:
[root@m01 scripts]# sh clearsyslog.sh -x
logs clean up successfully