-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailme
70 lines (58 loc) · 1.32 KB
/
mailme
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/bin/sh
# chkconfig: 2345 99 01
# Description: Sends an email at system start and shutdown
#############################################
# #
# Send an email on system start/stop to #
# a user. #
# #
#############################################
EMAIL="email"
RESTARTSUBJECT="Security Center - System Startup"
SHUTDOWNSUBJECT="Security Center - System Shutdown"
RESTARTBODY="This is an automated message to notify you that "`hostname`" started successfully.
Start up Date and Time: "`date`
SHUTDOWNBODY="This is an automated message to notify you that "`hostname`" is shutting down.
Shutdown Date and Time: "`date`
LOCKFILE=/var/lock/subsys/SystemEmail
RETVAL=0
# Source function library.
. /etc/init.d/functions
stop()
{
echo -n $"Sending Shutdown Email: "
echo "${SHUTDOWNBODY}" | mail -s "${SHUTDOWNSUBJECT}" ${EMAIL}
RETVAL=$?
if [ ${RETVAL} -eq 0 ]; then
rm -f ${LOCKFILE}
success
else
failure
fi
echo
return ${RETVAL}
}
start()
{
echo -n $"Sending Startup Email: "
echo "${RESTARTBODY}" | mailx -v -s "${RESTARTSUBJECT}" -S smtp="IP:25" ${EMAIL}
RETVAL=$?
if [ ${RETVAL} -eq 0 ]; then
touch ${LOCKFILE}
success
else
failure
fi
echo
return ${RETVAL}
}
case $1 in
stop)
stop
;;
start)
start
;;
*)
esac
exit ${RETVAL}