我的Sarg脚本

我的sarg脚本
每周日运行一次,出周报, 每过4周作一次日志rotate, 估计好使,特来分享。
 
01 23 * * 0 /usr/local/sarg/scripts/sargreport.sh
[root@proxy scripts]# cat sargreport.sh
#!/bin/bash
#Get current date
TODAY=$(date +%d/%m/%Y)
#Get one week ago today
#YESTERDAY=$(date --date "1 day ago" +%d/%m/%Y)
YESTERDAY=$(date --date "1 week ago" +%d/%m/%Y)
#YESTERDAY=$(date --date "1 month ago" +%d/%m/%Y)
sarg -z -d $YESTERDAY-$TODAY
cd /usr/local/sarg/scripts
#if line number =3 rotate squid log 每执行一次,在一个文件中加一行,第四次清空并rotate squid 日志
#if [ "$(awk '$0!~/^\s*$/{m++}END{print m}' counter.txt)" -ge 3 ]
if [ "$(grep -v "^\s*$" counter.txt | wc -l)" -eq 3 ]
then
        cat /dev/null > /usr/local/sarg/scripts/counter.txt
        su - squid -c "squid -k rotate"
else
        echo "1" >>  /usr/local/sarg/scripts/counter.txt
fi
 
#email通知周报生成
mail [email protected] -s $YESTERDAY-$TODAY  < weeklyreport.txt

#retate squid log
#su - squid -c "squid -k rotate"
exit 0

本文出自 “惟丑有才” 博客,转载请与作者联系!

你可能感兴趣的:(职场,squid,休闲)