Last active
December 24, 2016 15:08
-
-
Save thenewvu/11ff1a9789d5b014191bffcbe75ca3ec to your computer and use it in GitHub Desktop.
tail and grep a file, send mail when each line occurs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
sj=$1 | |
to=$2 | |
in=$3 | |
on=$4 | |
echo "sj=$sj" | |
echo "to=$to" | |
echo "in=$in" | |
echo "on=$on" | |
tail -fn 0 $in | | |
grep --line-buffered $on | | |
while read line | |
do | |
echo "$(date +%Y/%m/%d-%T%Z%z) - $line" | |
echo "$line" | mail -s $sj $to | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment