jeudi 14 décembre 2017

Bash script not working (if then else)

Please be kind, I'm not that great with bash yet.

I'm trying to read the last n lines of a file and email different subjects depending on the results. I have it half working however the else part is not wokring.

tail -n 2 -f $log |
grep --line-buffered completed. |
while read line; do
if [[  $line =~ completed. ]]; then
        echo "$line" | mailx -s "GOOD" user@domain
else
        echo "$line" | mailx -s "BAD" user@domain
fi
done

Aucun commentaire:

Enregistrer un commentaire