Skip to content

Instantly share code, notes, and snippets.

@thenewvu
Last active December 24, 2016 15:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thenewvu/11ff1a9789d5b014191bffcbe75ca3ec to your computer and use it in GitHub Desktop.
Save thenewvu/11ff1a9789d5b014191bffcbe75ca3ec to your computer and use it in GitHub Desktop.
tail and grep a file, send mail when each line occurs
#!/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