-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwd.sh
66 lines (52 loc) · 1.86 KB
/
wd.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/bin/sh
##########################################################################
# Yet Another Monitor (YAMon)
# Copyright (c) 2013-present Al Caughey
# All rights reserved.
###########################################################################
_sendAlerts=1 #Values: 0--> No || 1-->via usage-monitoring.com || 2-->using MSMTP if you have it in your firmware
_sendAlertTo=''
_debugging=0
d_baseDir=`dirname $0`
_configFile="$d_baseDir/config.file"
source "$_configFile"
source "${d_baseDir}/includes/versions.sh"
source "${d_baseDir}/includes/defaults.sh"
loadconfig
send2log()
{
local ts=$(date +"%H:%M:%S")
#echo "$ts $1" >> "$lfname"
[ "$_sendAlerts" -gt "0" ] && [ -z "$2" ] && sendAlert "$1" $ts
}
sendAlert()
{
local subj="$1"
local ts="$2"
local ds=$(date +"%Y-%m-%d %H:%M:%S")
msg="Running restart.sh @ $ts"
if [ "$_sendAlerts" -eq "1" ] ; then
subj=$(echo "$subj" | tr "'" '`')
msg=$(echo "$msg" | tr "'" '`')
local url="http://usage-monitoring.com/current/sendmail.php"
if [ -x /usr/bin/curl ] ; then
curl -G -sS "$url" --data-urlencode "t=$_sendAlertTo" --data-urlencode "s=$subj" --data-urlencode "m=$msg"
else
wget "$url?t=$_sendAlertTo&s=$subj&m=$msg" -q
fi
elif [ "$_sendAlerts" -eq "2" ] ; then
ECHO=/bin/echo
$ECHO -e "Subject: $subj\n\n$msg\n\n" | $_path2MSMTP -C $_MSMTP_CONFIG -a gmail $_sendAlertTo
fi
}
_cDay=$(date +%d)
_cMonth=$(date +%m)
_cYear=$(date +%Y)
lfpath="${d_baseDir}/$_logDir"
[ "${_logDir:0:1}" == "/" ] && lfpath=$_logDir
lfname="${lfpath}watchdog-$_cYear-$_cMonth-$_cDay.log"
[ ! -f "$lfname" ] && touch "$lfname"
np=$(ps | grep -v "grep" | grep -c "yam")
[ "$np" -eq "0" ] && send2log "Missing process..." && "$d_baseDir/restart.sh" 0 && exit
[ ! -d "$_lockDir" ] && send2log "Missing directory... $_lockDir" && "$d_baseDir/restart.sh" 0 && exit
send2log "Watchdog done" false