系统巡检脚本
要求如下:
请使用vmstat采集间隔1秒连续60秒得数据,汇总各项数据的平均值,一并形成一个报告。
答案:#! /bin/bash
## for vmstat 1 60 and get the average number.
## Writern by Aming.
comm="/usr/bin/vmstat"
f1="/tmp/1.txt"
f2="/tmp/2.txt"
f3="/tmp/3.txt"
$comm 1 60 >$f1
tail -n 60 $f1 >$f2
n=`awk '{print NF}' $f2 |head -n1`
echo "">$f3
for i in `seq 1 $n`; do
awk 'BEGIN {a=0}; {a=a+$"'$i'"};END{print a/NR}' $f2 >> $f3
done
cat $f1
echo "the average number is:"
echo "-----------------------------------------------------------------------------------"
cat $f3|xargs
请使用vmstat采集间隔1秒连续60秒得数据,汇总各项数据的平均值,一并形成一个报告。
答案:
## for vmstat 1 60 and get the average number.
## Writern by Aming.
comm="/usr/bin/vmstat"
f1="/tmp/1.txt"
f2="/tmp/2.txt"
f3="/tmp/3.txt"
$comm 1 60 >$f1
tail -n 60 $f1 >$f2
n=`awk '{print NF}' $f2 |head -n1`
echo "">$f3
for i in `seq 1 $n`; do
awk 'BEGIN {a=0}; {a=a+$"'$i'"};END{print a/NR}' $f2 >> $f3
done
cat $f1
echo "the average number is:"
echo "-----------------------------------------------------------------------------------"
cat $f3|xargs
none