清空varlog目录下的日志文件

xiaoxiao2026-06-11  6

#!/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 E_WRONGARGS=65 case "$1" in "" ) lines=50;; *[!0-9]*) echo "Usage:`basename $0` file-to cleanup";exit $E_WRONGARGS;; *) lines=$1;; esac #上面测试命令行参数的功能也可如下实现。但上面更好 #if [ -n "$1" ] #then # lines=$1 #else # lines=$LINES #fi cd $LOG_DIR tail -$lines messages > mesg.temp mv mesg.temp messages echo "Logs cleaned up." exit 0
转载请注明原文地址: https://www.6miu.com/read-5049993.html

最新回复(0)