I’m looking to grep a numeric value from a tripwire report, and if the value is greater than 0, send an email. The script so far looks like this:
#!/bin/bash tripwire --check > /tmp/twreport count=grep 'Total violations found: 0' /tmp/twreport if [ $count < 1 ]; then mail -s "[tripwire] Report for `uname -n`" user@example.com < /tmp/twreport fi
Not sure how to grab the value and set it as a variable or if there’s a way to include it in the if statement itself.
Advertisement
Answer
First count the entries:
count=`grep -c 'Total violations found' /tmp/twreport`
Next step is simple, e.g. for more than 3 hits:
if [ $count > 3 ] ; then mail -s “[tripwire] Report for `uname -n`” user@example.com