监控CPU和内存的使用:
#!/bin/bash #script to capture system statistics outfile=/home/rainbow/test/file.csv date=`date +%Y/%m/%d` time=`date +%k:%M:%S` timeout=`uptime` vmout=`vmstat 1 2` users=`echo $timeout|awk '{print $4}'` load=`echo $timeout|awk '{print $9}' |sed 's/,//'` free=`echo "$vmout"|sed -n '/[0-9]/p' |sed -n '2p'|awk '{print $4}'` idle=`echo "$vmout"|sed -n '/[0-9]/p' |sed -n '2p' |awk '{print $15}'` echo "$date,$time,$users,$load,$free,$idle">>$outfile
生成html文档的格式查看:
#!/bin/bash #parse capstats data info daily report FILE=/root/cimp/test TEMP=/root/cimp/test.html DATE=`date +"%A,%B %d, %Y"` echo "<html><body><h2>Report for $DATE</h2>" > $TEMP echo "<table border="1">" >> $TEMP echo "<tr><td>Date</td><td>Time</td><td>Users</td>" >> $TEMP cat $FILE |awk -F, '{printf "<tr><td>%s</td><td>%s</td><td>%s</td>",$1,$2,$3;print "<td>%s</td><td>%s</td><td>%s</td> </tr> ",$4,$5,$6}' >> $TEMP echo "</table></body></html>" >> $TEMP #rm -rf $TEMP