Last active
August 29, 2015 14:19
-
-
Save wnasich/ab20b63755a0fe3190b0 to your computer and use it in GitHub Desktop.
Report changes in log file by email
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/bash | |
# Adapted from http://stackoverflow.com/a/4657776/641892 | |
file=$1 | |
subject=$2 | |
size=0 | |
offset=0 | |
recipients="foo@bar" | |
if [[ $file =~ / ]]; then | |
echo "$0 does not accept path components in the file name" 2>&1 | |
exit 1 | |
fi | |
if [[ -e .offset.$file ]]; then | |
offset=$(<".offset.$file") | |
fi | |
if [[ -e $file ]]; then | |
size=$(stat -c "%s" "$file") # this assumes GNU stat, possibly present as gstat. CHECK! | |
# (gstat can also be Ganglias Status tool - careful). | |
fi | |
if (( $size < $offset )); then # file might have been reduced in size | |
echo "reset offset to zero" 2>&1 | |
offset=0 | |
fi | |
echo $size > ".offset.$file" | |
if [[ -e $file && $size -gt $offset ]]; then | |
tail -c +$(($offset+1)) "$file" | head -c $(($size - $offset)) | mail -s "$subject ($file)" $recipients | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment