Skip to content

Instantly share code, notes, and snippets.

@yath

yath/sendmail.sh

Created Apr 7, 2013
Embed
What would you like to do?
smartd mail script
#!/bin/sh
# send smartd mail plus serial and smartctl -a.
# usage: -m root -M exec /path/to/this/script
# test with: -m root -M exec /path/to/this/script -M test and smartctl -q onecheck afterwards.
tempfile=$(mktemp)
# message is passed via stdin
cat > $tempfile
# append smartctl -a
/usr/sbin/smartctl -a -d "$SMARTD_DEVICETYPE" "$SMARTD_DEVICE" >> $tempfile
SERIAL="$(hdparm -I "$SMARTD_DEVICE" | awk '/Serial Number/ { print $3 }')"
mail -s "$SMARTD_SUBJECT [$SERIAL $SMARTD_DEVICE]" $SMARTD_ADDRESS < $tempfile
rm -f "$tempfile"
# And exit
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.