From 43e8530e93493bb978c446a2023134bdd4277e50 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 19:14:45 +0200 Subject: Adding upstream version 7.4. Signed-off-by: Daniel Baumann --- examplescripts/Example1 | 44 ++++++++++++++++++++++++++++++++++++++ examplescripts/Example2 | 22 +++++++++++++++++++ examplescripts/Example3 | 27 +++++++++++++++++++++++ examplescripts/Example4 | 8 +++++++ examplescripts/Example5 | 10 +++++++++ examplescripts/Example6 | 33 ++++++++++++++++++++++++++++ examplescripts/Example7 | 26 ++++++++++++++++++++++ examplescripts/Example8 | 48 +++++++++++++++++++++++++++++++++++++++++ examplescripts/README | 57 +++++++++++++++++++++++++++++++++++++++++++++++++ 9 files changed, 275 insertions(+) create mode 100755 examplescripts/Example1 create mode 100755 examplescripts/Example2 create mode 100755 examplescripts/Example3 create mode 100755 examplescripts/Example4 create mode 100755 examplescripts/Example5 create mode 100755 examplescripts/Example6 create mode 100755 examplescripts/Example7 create mode 100755 examplescripts/Example8 create mode 100644 examplescripts/README (limited to 'examplescripts') diff --git a/examplescripts/Example1 b/examplescripts/Example1 new file mode 100755 index 0000000..070e87c --- /dev/null +++ b/examplescripts/Example1 @@ -0,0 +1,44 @@ +#! /bin/sh +# +# This is a script from the smartmontools examplescripts/ directory. +# It can be used as an argument to the -M exec Directive in +# /etc/smartd.conf, in a line like +# -m root@localhost -M exec /path/to/this/file +# +# Please see man 8 smartd or man 5 smartd.conf for further +# information. +# +# $Id: Example1 3958 2014-07-18 19:13:32Z chrfranke $ + +# Save standard input into a temp file +cat > /root/tempfile + +# Echo command line arguments into temp file +echo "Command line argument 1:" >> /root/tempfile +echo $1 >> /root/tempfile +echo "Command line argument 2:" >> /root/tempfile +echo $2 >> /root/tempfile +echo "Command line argument 3:" >> /root/tempfile +echo $3 >> /root/tempfile + +# Echo environment variables into a temp file +echo "Variables are": >> /root/tempfile +echo "$SMARTD_DEVICE" >> /root/tempfile +echo "$SMARTD_DEVICESTRING" >> /root/tempfile +echo "$SMARTD_DEVICETYPE" >> /root/tempfile +echo "$SMARTD_MESSAGE" >> /root/tempfile +echo "$SMARTD_FULLMESSAGE" >> /root/tempfile +echo "$SMARTD_ADDRESS" >> /root/tempfile +echo "$SMARTD_SUBJECT" >> /root/tempfile +echo "$SMARTD_TFIRST" >> /root/tempfile +echo "$SMARTD_TFIRSTEPOCH" >> /root/tempfile + +# Run smartctl -a and save output in temp file +/usr/sbin/smartctl -a -d $SMARTD_DEVICETYPE $SMARTD_DEVICE >> /root/tempfile + +# Email the contents of the temp file. Solaris and +# other OSes may need to use /usr/bin/mailx below. +/usr/bin/mail -s "SMART errors detected on host: `hostname`" $SMARTD_ADDRESS < /root/tempfile + +# And exit +exit 0 diff --git a/examplescripts/Example2 b/examplescripts/Example2 new file mode 100755 index 0000000..6882164 --- /dev/null +++ b/examplescripts/Example2 @@ -0,0 +1,22 @@ +#! /bin/sh +# +# This is a script from the smartmontools examplescripts/ directory. +# It can be used as an argument to the -M exec Directive in +# /etc/smartd.conf, in a line like +# -m root@localhost -M exec /path/to/this/file +# +# Please see man 8 smartd or man 5 smartd.conf for further +# information. +# +# $Id: Example2 3958 2014-07-18 19:13:32Z chrfranke $ + +# Save the email message (STDIN) to a file: +cat > /root/msg + +# Append the output of smartctl -a to the message: +/usr/sbin/smartctl -a -d $SMARTD_DEVICETYPE $SMARTD_DEVICE >> /root/msg + +# Now email the message to the user. Solaris and +# other OSes may need to use /usr/bin/mailx below. +/usr/bin/mail -s "$SMARTD_SUBJECT" $SMARTD_ADDRESS < /root/msg + diff --git a/examplescripts/Example3 b/examplescripts/Example3 new file mode 100755 index 0000000..d23a6a5 --- /dev/null +++ b/examplescripts/Example3 @@ -0,0 +1,27 @@ +#! /bin/sh +# +# This is a script from the smartmontools examplescripts/ directory. +# It can be used as an argument to the -M exec Directive in +# /etc/smartd.conf, in a line like +# -m -M exec /path/to/this/file +# +# Please see man 8 smartd or man 5 smartd.conf for further +# information. +# +# $Id: Example3 3958 2014-07-18 19:13:32Z chrfranke $ + +# Warn all users of a problem +wall <Your hard disk drive is failing! +S.M.A.R.T. message: +$SMARTD_MESSAGE" diff --git a/examplescripts/Example5 b/examplescripts/Example5 new file mode 100755 index 0000000..a85961c --- /dev/null +++ b/examplescripts/Example5 @@ -0,0 +1,10 @@ +#!/bin/bash -e + +tmp=$(tempfile) +cat >$tmp + +run-parts --report --lsbsysinit --arg=$tmp --arg="$1" \ + --arg="$2" --arg="$3" -- /etc/smartmontools/run.d + +rm -f $tmp + diff --git a/examplescripts/Example6 b/examplescripts/Example6 new file mode 100755 index 0000000..d1217e1 --- /dev/null +++ b/examplescripts/Example6 @@ -0,0 +1,33 @@ +#! /bin/sh + +# Send mail +if which mail >/dev/null 2>&1 +then + echo "$SMARTD_FULLMESSAGE" | mail -s "$SMARTD_SUBJECT" "$SMARTD_ADDRESS" +fi + +# Notify desktop user +MESSAGE="SMART Disk monitor:" +case "$SMARTD_FAILTYPE" in + "EmailTest"|"Health"|"Temperature"|"Usage") + ;; + *) +# "CurrentPendingSector", // 10 +# "OfflineUncorrectableSector", // 11 +# "FailedReadSmartErrorLog", // 7 +# "ErrorCount", // 4 +# "FailedReadSmartData", // 6 +# "FailedHealthCheck", // 5 +# "FailedOpenDevice", // 9 +# "SelfTest", // 3 +# "FailedReadSmartSelfTestLog", // 8 + exit 0 +esac + +# direct write to terminals, do not use 'wall', because we don't want its ugly header +for t in $(who | awk '{ print $2; }' | grep -e '^tty' -e '^pts/') +do + echo "$MESSAGE +$SMARTD_MESSAGE" >/dev/$t 2>/dev/null ||: +done + diff --git a/examplescripts/Example7 b/examplescripts/Example7 new file mode 100755 index 0000000..7766b4b --- /dev/null +++ b/examplescripts/Example7 @@ -0,0 +1,26 @@ +#! /bin/sh +# +# This is a script from the smartmontools examplescripts/ directory. +# It can be used as an argument to the -M exec Directive in +# /etc/smartd.conf, in a line like +# ... -m root@localhost -M exec /path/to/this/file +# +# See also: smartd.conf(5), smartd(8). +# +# $Id: Example7 5442 2023-01-26 18:15:26Z chrfranke $ + +if [ $# -lt 3 ] || [ "$1" != "-s" ]; then + echo "Usage: $0 -s SUBJECT ADDRESS... < MESSAGE" + exit 1 +fi + +SUBJECT=$2 +shift; shift +ADDRESS=$* + +exec /usr/sbin/sendmail $ADDRESS <' is set +test -n "$SMARTD_ADDRESS" || exit 0 + +# Try mail[x] +# Note: The 'command -v' builtin requires a POSIX >= 2008 conforming shell +for mailer in \ + $(command -v mail 2>/dev/null) \ + $(command -v mailx 2>/dev/null) \ + /usr/bin/mail \ + /usr/bin/mailx +do + test -f "$mailer" || continue + test -x "$mailer" || continue + exec "$mailer" -s "${SMARTD_SUBJECT-[SMARTD_SUBJECT]}" $SMARTD_ADDRESS <, +and include a brief description to use below. + +The files contained in this directory are: + +Example1: Appends values of $SMARTD_* environment variables and the output + of smartctl -a to the normal email message, and sends that + to the email address listed as the argument to the -m + Directive. + +Example2: Appends output of smartctl -a to the normal email message + and sends that to the email address listed as the argument + to the -m Directive. + +Example3: Uses wall(1) to send a warning message to all users, then powers + down the machine. + +Example4: Uses powersave-notify to issue a desktop neutral warning. + (/etc/smartmontools/run.d/10powersave-notify from Debian package) + +Example5: Uses run-parts(8) to run scripts from /etc/smartmontools/run.d/. + (/usr/share/smartmontools/smartd-runner from Debian package) + +Example6: Sends a warning mail and then notifies the users by direct write + to terminals. + (/usr/libexec/smartmontools/smartdnotify from Fedora package) + +Example7: Sends an email using /usr/sbin/sendmail mail transfer agent. + May be useful if there is no other mail(1) compatible mailer + available. + +Example8: Sends an email using mail, mailx or sendmail mail transfer agent, + whichever is found first. This script uses SMARTD_* environment + variables and could therefore also be used in a run-parts(8) + context like Example5. -- cgit v1.2.3