bash - Linux Script: How to check for any lines that starts with but not contain -
i'm @ following directory...
/var/log/homes
and script check lines starts 'error' , contains word 'notauthorized' , not contains '13024' or '31071'.
within /var/log/homes/, there 700 files, doesn't matter...
below have...
#!/bin/bash host=`hostname` date=`date` monitor='error' pattern='error' pattern2='notauthorized' ignore=13024 ignore2=31071 logfile='/var/log/homes/*' mailto='test@linux.com' if [ -e $logfile ] if [ `grep -i "$pattern" "$pattern2" "$logfile" | grep -v $ignore $ignore ] echo "errors found in $monitor @ $date - see log $logfile on server $host full details" |mail -s "alert - $errors in logs, please review" $mailto elif [ `grep -i "$pattern2" "$logfile" |wc -l` -lt 1 ] fi else echo "logfile $logfile doesn't exist on server $host @ $date, bad, please investigate" |mail -s "alert - $monitor monitor has issue" $mailto fi
this should work:
grep "^error" $logfile | grep "notauthorized" | grep -v "13024" | grep -v "31071"
grep "^error"
: lines starting ith "error"grep "notauthorized"
: lines containing "notauthorized"grep -v "xxx"
: lines not containing "xxx"
Comments
Post a Comment