Created
September 3, 2013 19:08
-
-
Save jimkang/6428217 to your computer and use it in GitHub Desktop.
Bash script that emails what you pipe to it via stdin. (Probably a jillion of these out there; so many that I had trouble Googling one.) Example usage: tail /var/logs/stuff.log | ./mailstuff.sh
This file contains 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/bash | |
# Mails whatever it gets from stdin. | |
to="you@your.org" | |
subject="Something is happening on $HOSTNAME" | |
body="The first line of the email body.\n"; | |
while read -r line; do | |
[[ $line = \#* ]] && continue | |
body="$body$line\n" | |
done < /dev/stdin | |
echo -e $body | mail -s "$subject" $to |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment