forked from VKoorits/BOS_lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checker.sh
executable file
·71 lines (59 loc) · 1.23 KB
/
checker.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
#!/bin/bash
CONF=/opt/checker/checker.conf
IFS=":"
timeout=60
pidFile=/opt/checker/checker.pid
echo $$ > $pidFile
function Log {
systemd-cat echo $1
}
function checkPaermission {
realPerm=$( find $FILE -printf '%m' )
if [[ $realPerm != $REST ]]
then
Log "CHECKER ERROR: Expected $REST Got $realPerm for $FILE"
chmod $REST $FILE
fi
}
function checkUser {
user=$( find $FILE -printf '%u\n' )
if [ "$user" != "$USER" ]
then
Log "CHECKER ERROR: Expected $USER Got $user for $FILE"
chown $USER $FILE
fi
}
function checkGroup {
group=$( find $FILE -printf '%g\n' )
if [ "$group" != "$GROUP" ]
then
chgrp $GROUP $FILE
Log "CHECKER ERROR: Expected $GROUP Got $group for $FILE"
fi
}
function MainCheck {
Log "CHECKER: Scanning is beginning"
while read FILE REST USER GROUP
do
checkPaermission $FILE $REST
checkUser $FILE $USER
checkGroup $FILE $GROUP
done < $CONF
Log "CHECKER: Scanning is successfully complited"
# Log "PID=$$"
}
function CheckBySignal {
Log "SIGUSR1"
MainCheck
}
function onexit {
Log "Exit"
}
trap "CheckBySignal" SIGUSR1
trap "onexit" EXIT
while true
do
Log "Start service"
wait && MainCheck
sleep $timeout &
done