使用Shell指令碼刪除 清空日誌檔案

2022-08-24 22:15:10 字數 850 閱讀 1752

話不多少,直接上**:

#!/bin/bash

workdir=("/home/tax_punish_ret/log_txt") #

可填寫多個路徑

, 用空格隔開

# 查詢日誌檔案

for wdir in $

doecho filepath is $wdir

if [ $wdir = $ ] ;then

filestr=`find $wdir/*.log`

echo files is $filestr

else

filestr=`find $wdir -type d`

echo filee is $filestr

fi# 刪除/

清空日誌檔案

for dir in $filestrdo

echo file name is $dir

# 清空不刪除日誌檔案

echo ''>$dir

# 刪除日誌檔案

#find $dir -name '*log*' -and -mtime +7 -type f | xargs rmif [ $? -eq 0 ];then

echo $date delete $dir success!

else

echo $date delete $dir faild!

fidone

done

crontab 執行定時指令碼:

* * * * * /bin/bash /home/ubuntu/deletelog.sh >> /home/ubuntu/deletelog.txt 2>&1&

使用Shell指令碼刪除 清空日誌檔案

話不多少,直接上 bin bash workdir home tax punish ret log txt 可填寫多個路徑,用空格隔開 查詢日誌檔案 for wdir in do echo filepath is wdir if wdir then filestr find wdir log ech...

select Option 增加,刪除,清空

select id change function 為select新增事件,當選擇其中一項時觸發 var checktext select id find option selected text 獲取select選擇的text var checkvalue select id val 獲取sele...

shell指令碼清空系統message日誌

1 bin bash 2 此指令碼用來清空系統message日誌檔案 3 author wyf date 16 10 30 4 log dir var log 5 root uid 0 6 必須系統管理員許可權才能執行 7 if uid ne 8 then 9 echo must be root t...