ffmpeg-6: fix COMPONENT_REVISION
[oi-userland.git] / components / sysutils / nut / files / notifyme
blobb7e8129373d625557cd17c382790b7828f9b32db
1 #!/bin/sh
3 # Called by upsmon when important things happen
4 # Env contains UPSNAME like "ups1@localhost",
5 # a NOTIFYTYPE like "ONLINE", and $1="My message"
6 # (C) 2000-2006,2016 by Jim Klimov
8 LANG=C
9 LC_ALL=C
10 TZ=UTC
11 export LANG LC_ALL TZ
13 [ -s /etc/nut/notifyme.conf ] && . /etc/nut/notifyme.conf
15 # By default, we send a message to root@localhost and a syslog event
16 [ -n "${MAILPROG-}" ] || MAILPROG="mail"
17 [ -n "${UPSMONNAMELONG-}" ] || UPSMONNAMELONG="the UPSMon-`hostname`"
19 [ -n "${UPSMON_SYSLOGPRIO_TROUBLE-}" ] || UPSMON_SYSLOGPRIO_TROUBLE="daemon.emerg"
20 [ -n "${UPSMON_SYSLOGPRIO_GOODNOW-}" ] || UPSMON_SYSLOGPRIO_GOODNOW="$UPSMON_SYSLOGPRIO_TROUBLE"
21 #[ -n "${UPSMON_SYSLOGPRIO_GOODNOW-}" ] || UPSMON_SYSLOGPRIO_GOODNOW="daemon.notice"
23 # Additionally, we can send a short SMS via email, if the admin has it set up
24 # SMSMAIL="sms2mail.account@mobile.operator"
25 [ -n "${SMSMAIL-}" ] || SMSMAIL=""
26 [ -n "${UPSMONNAMESMS-}" ] || UPSMONNAMESMS="UPSMon@`hostname`"
28 now="`date -u '%Y-%m-%d %H:%M:%S'`"
29 message="$1"
30 plea=""
31 [ x"$NOTIFYTYPE" != xONLINE -a x"$NOTIFYTYPE" != xCOMMOK ] && plea="
32 Please do something with power!
33 My shutdown will be clean, but...
36 # 1) Alert all consoles, syslog (and maybe email - depending on syslog daemon)
37 if [ -x /usr/bin/logger ]; then
38 [ -n "$plea" ] && \
39 SYSLOG_PRIO="$UPSMON_SYSLOGPRIO_TROUBLE" || \
40 SYSLOG_PRIO="$UPSMON_SYSLOGPRIO_GOODNOW"
41 /usr/bin/logger -p "$SYSLOG_PRIO" -t "upsmon.notifyme.$$" "$UPSNAME: $NOTIFYTYPE : $message (at $now)" "$plea"
44 case "$MAILPROG" in
45 "") ;;
46 /*) ;;
47 *) MAILPROG="`which "$MAILPROG" | head -1 | egrep '^/'`" ;;
48 esac
50 [ -n "$MAILPROG" ] || exit 0
51 [ -x "$MAILPROG" ] || { echo "ERROR: MAILPROG='$MAILPROG' was specified but is not executable">&2; exit 1; }
53 # 2) send local mail so I know when the $it has hit the fan
54 # If it's local power trouble in the serverroom,
55 # I might go fix it before it's too late :^)
56 ${MAILPROG} root -s "UPS status change: $NOTIFYTYPE" << EOF
57 $UPSNAME
58 $now
59 UPS status change: $NOTIFYTYPE
61 $message
62 $plea
63 Sincerely, $UPSMONNAMELONG
64 EOF
66 if [ -n "${SMSMAIL-}" ]; then
67 # 3) Send an SMS to the admin
68 ${MAILPROG} "$SMSMAIL" -s "UPS!" << EOF
69 $now
70 $UPSNAME: $NOTIFYTYPE
71 $message
72 //$UPSMONNAMESMS
73 EOF