Skip to content

Instantly share code, notes, and snippets.

@jimkang
Created September 3, 2013 19: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 jimkang/6428217 to your computer and use it in GitHub Desktop.
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
#!/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