-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdog_system.sh
executable file
·93 lines (84 loc) · 1.79 KB
/
dog_system.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/bin/sh
######################################
# System Watch Dog
# check system important service
# !!! suppose to be run every 5 minutes !!!
# by jimmy 20071023
debug=1
permonth=8640
perweek=2016
perday=288
perhour=12
if [ `date +"%u"` -lt 6 ]; then
weekend=0
else
weekend=1
fi
if [ `date +"%k"` -lt 22 -a `date +"%k"` -gt 8 ]; then
rushhour=0
else
rushhour=1
fi
###
### Check Basic Service
###
number=$RANDOM
let "number %= $perhour"
if [ $number == 0 ];then
if [ -n "`/bin/ps -e | grep snmpd`" ]; then
echo "snmp still going"
else
/etc/rc.d/init.d/snmpd start
date >> /YOKA/important_log
echo "snmpd stoped, reload snmpd." >> /YOKA/important_log
fi
if [ -n "`/bin/ps -e | grep sshd`" ]; then
echo "sshd still going"
else
/usr/local/sbin/sshd
date >> /WORK/important_log
echo "sshd stoped, reload sshd." >> /WORK/important_log
fi
fi
###
### Restart Basic Service
###
number=$RANDOM
let "number %= $perweek"
if [ $number == 0 ];then
/etc/rc.d/init.d/snmpd restart
fi
###
# Clean Mail
###
number=$RANDOM
let "number %= $perweek"
if [ $number == 0 ];then
echo "" > /var/spool/mail/root
fi
###
# Clean Error Log
###
number=$RANDOM
let "number %= $perweek"
if [ $number == 0 ];then
log_path="/WORK/important_log"
tail -n 20 $log_path > /tmp/error_log.tmp
cat /tmp/error_log.tmp > $log_path
log_path="/WORK/LOG/apachelogs"
for file in `ls $log_path | grep error_log`
do
if [ -f $log_path/$file ]; then
tail -n 1000 $log_path/$file > /tmp/error_log.tmp
cat /tmp/error_log.tmp > $log_path/$file
fi
done
log_path="/WORK/LOG/phplogs"
for file in `ls $log_path | grep error_log`
do
if [ -f $log_path/$file ]; then
tail -n 1000 $log_path/$file > /tmp/error_log.tmp
cat /tmp/error_log.tmp > $log_path/$file
fi
done
fi