#!/bin/bash
#
#
export LANG=en_US.utf8
sum=0
num=`ls /extend/log|wc -l `
D1=`date +%Y%m%d`
D2=`date +%Y%m%d --date "1 days ago"`
D3=`date +%Y%m%d --date "2 days ago"`
D4=`date +%Y%m%d --date "3 days ago"`
D5=`date +%Y%m%d --date "4 days ago"`
D6=`date +%Y%m%d --date "5 days ago"`
D7=`date +%Y%m%d --date "6 days ago"`
D8=`date +%Y%m%d --date "7 days ago"`
echo "+++++++++++++++ all $num ++++++++++++++++" > /var/www/html/loglist
cd /extend/log/
#find . -name \*-$date-*.gz >> /tmp/loglist1
ls * >> /var/www/html/loglist
#num_new=`ls log/ -lrt|grep "Jan 27"|wc -l`
#ls log/ -lrt|grep "Jan 27"|awk '{print $9}' >>/var/www/html/loglist
#for i in `ls log/ -lrt|grep "Jan 27"|awk '{print $9}'`
#do
#echo $i >>/tmp/loglist2
#done
#echo "+++++++++++++++new ++++++++++++++++" > /tmp/loglist2
echo "SN,$D2,$D3,$D4,$D5,$D6,$D7,$D8" > /tmp/logstatus.csv
for i in `ls /extend/log/|grep -v diwei|grep -v hostslog|grep -v HH00000000000000`
do
echo -n "$i" >> /tmp/logstatus.csv
for d in {$D1,$D2,$D3,$D4,$D5,$D6,$D7}
do
if ls $i/$i-$d*.gz &> /dev/null
then
echo -n ",Y" >> /tmp/logstatus.csv
else
echo -n ",">> /tmp/logstatus.csv
fi
done
echo >> /tmp/logstatus.csv
#num=`ls /extend/log/$i|wc -l`
#line=`ls /extend/log/$i`
#if [ $num -eq 1 ]
#then
#sum=$(($sum+1))
#echo -n " " >> /tmp/loglist2
#echo $i >> /tmp/loglist2
#fi
done
## sum logstatus.csv
#明天需要取日志的盒子(前两天都没有日志传回)
sn=`awk -F "," '{if ($1!="SN" && $2=="" && $3==""){print $1,$2,$3}}' /tmp/logstatus.csv`
#盒子总数
box_sum_tmp=`cat /tmp/logstatus.csv|wc -l`
box_sum=$(($box_sum_tmp-1))
boxneed=`awk -F "," '{if ($1!="SN" && $2=="" && $3==""){print $1,$2,$3}}' /tmp/logstatus.csv|wc -l`
boxno=$(($box_sum-$boxneed))
#echo "+++++++++++++++ new $sum ++++++++++++++++" >> /tmp/loglist2
#paste /tmp/loglist1 /tmp/loglist2 &> /var/www/html/loglist
echo "** Y:表示有日志,每天23点发送" > /tmp/mail.log
echo "** 全部盒子的日志状态详见附件" >> /tmp/mail.log
echo "** 盒子总数:$box_sum" >> /tmp/mail.log
echo "** 明天\"无需\"取日志的盒子数:$boxno" >> /tmp/mail.log
echo "** 明天\"需要\"取日志的盒子数:$boxneed" >> /tmp/mail.log
echo "** 明天需要取日志的盒子(前两天都没有日志传回的盒子):" >>/tmp/mail.log
echo "$sn" >> /tmp/mail.log
cat /tmp/mail.log|mailx -s "日志状态" -a /tmp/logstatus.csv test@163.com
转载于:https://blog.51cto.com/lejie/1838000