-
Notifications
You must be signed in to change notification settings - Fork 11
/
emailstopstart.sh
49 lines (43 loc) · 1.1 KB
/
emailstopstart.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/bin/bash
#
# emailstartstop Send an email on server startup and shutdown.
#
# chkconfig: 2345 99 01
# description: Send an email on server startup and shutdown.
EMAIL="{{ email_ids }}"
STARTSUBJ="{{ project }} started on `date`"
STARTBODY="Just letting you know that server "`hostname`" has started on "`date`
STOPSUBJ="{{ project }} shutdown on `date`"
STOPBODY="Just letting you know that server `hostname` has shutdown on `date` {{ inventory_hostname }}"
lockfile=/var/lock/subsys/emailstartstop
# Send email on startup
start() {
echo -n $"Sending email on startup: "
echo "${STARTBODY}" | mail -s "${STARTSUBJ}" ${EMAIL}
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch $lockfile
return 0
}
# Send email on shutdown
stop() {
echo -n "Sending email on shutdown: "
echo "${STOPBODY}" | mail -s "${STOPSUBJ}" ${EMAIL}
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $lockfile
return 0
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
*)
echo $"Usage: $prog {start|stop}"
exit 2
esac
exit ${RETVAL}