diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:14:45 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 17:14:45 +0000 |
commit | 43e8530e93493bb978c446a2023134bdd4277e50 (patch) | |
tree | e8c0d3c0c394b17381f48fb2d288f166b4f22440 /examplescripts | |
parent | Initial commit. (diff) | |
download | smartmontools-43e8530e93493bb978c446a2023134bdd4277e50.tar.xz smartmontools-43e8530e93493bb978c446a2023134bdd4277e50.zip |
Adding upstream version 7.4.upstream/7.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-x | examplescripts/Example1 | 44 | ||||
-rwxr-xr-x | examplescripts/Example2 | 22 | ||||
-rwxr-xr-x | examplescripts/Example3 | 27 | ||||
-rwxr-xr-x | examplescripts/Example4 | 8 | ||||
-rwxr-xr-x | examplescripts/Example5 | 10 | ||||
-rwxr-xr-x | examplescripts/Example6 | 33 | ||||
-rwxr-xr-x | examplescripts/Example7 | 26 | ||||
-rwxr-xr-x | examplescripts/Example8 | 48 | ||||
-rw-r--r-- | examplescripts/README | 57 |
9 files changed, 275 insertions, 0 deletions
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 <nomailer> -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 <<EOF +Problem detected with disk: $SMARTD_DEVICESTRING +Warning message from smartd is: $SMARTD_MESSAGE +Shutting down machine in 30 seconds... +EOF + +# Wait half a minute +sleep 30 + +# Power down the machine (uncomment the shutdown command if you really +# want to do this!) + +# /sbin/shutdown -hf now + diff --git a/examplescripts/Example4 b/examplescripts/Example4 new file mode 100755 index 0000000..4aaebbc --- /dev/null +++ b/examplescripts/Example4 @@ -0,0 +1,8 @@ +#! /bin/sh + +# Send message if /usr/lib/powersave/powersave-notify exists or exit silently +[ -x /usr/lib/powersave/powersave-notify ] || exit 0 + +/usr/lib/powersave/powersave-notify "<b>Your hard disk drive is failing!</b> +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 <<EOF +Subject: $SUBJECT +To: $(echo $ADDRESS | sed 's/ /, /g') + +$(cat -) +EOF diff --git a/examplescripts/Example8 b/examplescripts/Example8 new file mode 100755 index 0000000..e30ffaf --- /dev/null +++ b/examplescripts/Example8 @@ -0,0 +1,48 @@ +#! /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: Example8 5404 2022-08-06 17:15:49Z chrfranke $ + +# Skip if '-m <nomailer>' 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 <<EOF +${SMARTD_FULLMESSAGE-[SMARTD_FULLMESSAGE]} +EOF + exit $? +done + +# Try sendmail +for sendmail in \ + /usr/sbin/sendmail \ + /usr/lib/sendmail +do + test -f "$sendmail" || continue + test -x "$sendmail" || continue + exec "$sendmail" $SMARTD_ADDRESS <<EOF +Subject: ${SMARTD_SUBJECT-[SMARTD_SUBJECT]} +To: $(echo $SMARTD_ADDRESS | sed 's/ /, /g') + +${SMARTD_FULLMESSAGE-[SMARTD_FULLMESSAGE]} +EOF + exit $? +done + +echo "$0: found none of 'mail', 'mailx' or 'sendmail'" +exit 1 diff --git a/examplescripts/README b/examplescripts/README new file mode 100644 index 0000000..bf67b54 --- /dev/null +++ b/examplescripts/README @@ -0,0 +1,57 @@ +# Home page: http://www.smartmontools.org +# +# $Id: README 4937 2019-08-04 15:29:43Z chrfranke $ +# +# Copyright (C) 2003-08 Bruce Allen +# Copyright (C) 2009-18 Christian Franke +# +# SPDX-License-Identifier: GPL-2.0-or-later +# + +This directory contains executable shell scripts, that are intended for +use with the + -m address -M exec /path/to/an/executable +Directive in /etc/smartd.conf. + +Details about how to use this Directive may be found in the man pages for +smartd and smartd.conf. + man 8 smartd + man 5 smartd.conf +should display those pages on your system. + +If you wish to contribute additional scripts to this collection, +please email them to <smartmontools-support@listi.jpberlin.de>, +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. |