1#! /bin/sh
2#
3# This is a script from the smartmontools examplescripts/ directory.
4# It can be used as an argument to the -M exec Directive in
5# /etc/smartd.conf, in a line like
6# ... -m root@localhost -M exec /path/to/this/file
7#
8# See also: smartd.conf(5), smartd(8).
9#
10# $Id: Example8 4937 2019-08-04 15:29:43Z chrfranke $
11
12# Skip if '-m <nomailer>' is set
13test -n "$SMARTD_ADDRESS" || exit 0
14
15# Try mail[x]
16for mailer in \
17  $(which mail 2>/dev/null) \
18  $(which mailx 2>/dev/null) \
19  /usr/bin/mail \
20  /usr/bin/mailx
21do
22  test -f "$mailer" || continue
23  test -x "$mailer" || continue
24  exec "$mailer" -s "${SMARTD_SUBJECT-[SMARTD_SUBJECT]}" $SMARTD_ADDRESS <<EOF
25${SMARTD_FULLMESSAGE-[SMARTD_FULLMESSAGE]}
26EOF
27  exit $?
28done
29
30# Try sendmail
31for sendmail in \
32  /usr/sbin/sendmail \
33  /usr/lib/sendmail
34do
35  test -f "$sendmail" || continue
36  test -x "$sendmail" || continue
37  exec "$sendmail" $SMARTD_ADDRESS <<EOF
38Subject: ${SMARTD_SUBJECT-[SMARTD_SUBJECT]}
39To: $(echo $SMARTD_ADDRESS | sed 's/ /, /g')
40
41${SMARTD_FULLMESSAGE-[SMARTD_FULLMESSAGE]}
42EOF
43  exit $?
44done
45
46echo "$0: found none of 'mail', 'mailx' or 'sendmail'"
47exit 1
48