分类:
2005-09-08 12:04:45
以下為shell的內容:
=================================================
cat count_con.sh
#!/bin/ksh
#
cd $HOME
#unset count_sz count_dg count_tw
/u1/fgl2c.run/bin/fglWrt -a info user 2> $HOME/count_con.txt
cat $HOME/count_con.txt | grep "GUI Server 10.7" > $HOME/con_sz.txt
cat $HOME/count_con.txt | grep "GUI Server 10.6" > $HOME/con_dg.txt
cat $HOME/count_con.txt | grep "GUI Server 10.3" >> $HOME/con_dg.txt
cat $HOME/count_con.txt | grep "GUI Server 10.5" >> $HOME/con_dg.txt
cat $HOME/count_con.txt | grep "GUI Server 10.1" > $HOME/con_tw.txt
cat $HOME/count_con.txt | grep "GUI Server 10.2" >> $HOME/con_tw.txt
count_sz=`cat $HOME/con_sz.txt | wc -l`
count_dg=`cat $HOME/con_dg.txt | wc -l`
count_tw=`cat $HOME/con_tw.txt | wc -l`
count_time=`date`
echo "==========================================================" >> $HOME/count.log
#echo "##" >> $HOME/count.log
echo "Begin Time " + $count_time >> $HOME/count.log
grep Users count_con.txt >> $HOME/count.log
echo "SuZhou Count " "DongGuan Count " "TaiWan Count" >>$HOME/count.log
echo $count_sz " " $count_dg " " $count_tw >>$HOME/count.log
#echo "##" >> $HOME/count.log
====================================================
將寫好的shell放到crontab中執行,每15分鐘執行一次
crontab -l
6,21,36,51 * * * * sh /home/yahsin/count.sh
為對此統計結果進行統計,當然是將資料放入到excel中,然後作成圖表形式最好了
以下是實現步驟:
cat count.log | sed -n '/^Begin/p' | awk '{print $ 4,$ 5,$ 6,$ 7}' > count_time.log
cat count.log | sed -n '/^[0-9]/p' > count_num.log
paste -d " " count_time.log count_num.log > count_hb.log
再將結果發送到自己的郵箱中
mail –s mail -s "count_hb.log" mymail@mymail.com < count_hb.log
將收到的mail內容複製到文本文件中,
然後用excel打開這個文件,再作一些數據分析的圖表就ok了
=====================================================
后記:
取log中的ip列表
cat count_con.txt | grep GUI | awk '{print $3}' | cut -d ':' -f1 | sort | uniq > ip_list.txt