
我有下面的腳本來檢查日誌檔案的大小。如果它成長到超過 84M,則應使用當前日期重新命名,並且我的應用程式會自動產生一個新的。但是它不會使用 cron 任務自動運行。幫我新增程式碼來檢查是否達到 84M 向我發送電子郵件,然後我可以手動執行腳本。
#!/bin/bash
#Andrew O. MBX 2016-01-26
#HansaWorld Script to Check Size of Hansa.log file
# and move it to a new folder HansaLogs
tstamp=$(date "+%m%d%Y") #Set Timestamp
logdir="/u/HansaWorldLive/HansaLogs" #Set path to where hansa.log will be moved
logname="/u/HansaWorldLive/hansa.log" #Set Path to hansa.log file
maximumsize= +83500K #Set maximumsize
actualsize=$(wc -c<"$logname")
if [ $actualsize -ge $maximumsize ]; then
mv "$logname" "$logdir/hansa_${tstamp}.log" #Move the Log file and rename by adding timestamp
else
echo size is under $maximumsize bytes
exit 1
fi