Skip to content

Instantly share code, notes, and snippets.

@yath
Created April 7, 2013 06:09
Show Gist options
  • Save yath/5329253 to your computer and use it in GitHub Desktop.
Save yath/5329253 to your computer and use it in GitHub Desktop.
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