我需要编写一个shell脚本来grep错误并写入文件并检查错误发生的次数/次数。如果计数超过一个数字,那么应该邮寄带有详细信息的错误。到目前为止已经写了这个但无法继续..请帮助
#!/bin/bash
h1=`hostname`
d1=`date`
XYZLOGS=<dir@ which log located>s
for fname in $XYZLOGS
do
XYZ=$(basename $fname)
f=${fname}/XYZLog.log
var=`tail -5000 $f | grep "Server Error" -C 20`
echo "$var" >/tmp/XYZlogcopy.txt
var1=`tail -5000 $f | grep "Server Error" |wc -l`
if [$var1 -eq "5"] ;
then
if [ ! -z "$var" ] ;
then
echo "$var error on $cbp on server $h1 @ $d1" | mailx -s "error on $xyz" <mail address>
break
else
echo "No matching error found on server $h1 @ $d1" >>/tmp/jobrun.txt
fi
fi
done