#!/bin/bash
#清除日志脚本
LOG_DIR=/var/log
ROOT_UID=0 #$UID为0的时候,用户具有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
exit 1
}
cat /dev/null >messages &&echo "logs cleaned up"
exit 0
时间: 2024-10-12 16:22:40