日誌清理 sh

2021-06-21 11:44:07 字數 1165 閱讀 4556

#!/bin/bash

log_dir=/var/log

root_uid=0

lines=50

e_xcd=66

e_notroot=67

e_wrongargs=65

if [ "$uid" -ne "$root_uid" ]

then

echo "must be root to run this script."

exit $e_notroot

fi#echo "$1"

#if [ -z "$1" ]                            #-z str : str為null,長度為0    -n str : str不為空

#then

#lines=$lines

#echo "沒有引數,預設保留50行"

#else

#lines=$1

#echo "帶有引數 保留行數為$lines"

#ficase "$1" in

"" ) lines=50;

echo "沒有引數,預設保留50行";;

*[!0-9]*) echo "usage: `basename $0` failed-to-cleanup 引數錯誤!" >log 2>&1;

exit $e_wrongargs;;

* ) lines=$1;

echo "帶有引數 保留行數為$lines";;

esac

#cd $log_dir

#if [ `pwd` != "$log_dir" ]                # if[ "$pwd" != "$log_dir" ]

#then

#echo "can't change to $log_dir."

#exit $e_xcd

#ficd $log_dir ||

#tail -$lines messages > mesg.temp      # cat /dev/null > messages

#mv mesg.temp messages

#cat /dev/null > wtmp                     # ': > wtmp' 和 '> wtmp'具有相同的作用

echo "logs cleaned up."

exit 0

清理登入日誌

root localhost root echo var log wtmp 此檔案預設開啟時亂碼,可查到ip等資訊 root localhost root last 此時即查不到使用者登入資訊 清除登陸系統失敗的記錄 root localhost root echo var log btmp 此檔案...

logrotate清理日誌

清理日誌 logrotate配置目錄 etc logrotate.d 配置引數資訊 引用文字 monthly monthly 日誌檔案將按月輪循。其它可用值為 daily weekly yearly size 50m 日誌檔案大小可以增長到50m rotate 5 一次將儲存5個歸檔日誌。對於第六個...

docker清理日誌

docker 用久了 日誌一大堆,很占用空間,不用的日誌可以清理掉了。docker logs f container name 噼里啪啦 一大堆,太對,清理掉 找到對應container的日誌檔案,一般是在 var lib docker containers containerid containe...