-
Notifications
You must be signed in to change notification settings - Fork 2
/
kontrollflerefiler.sh
executable file
·79 lines (64 loc) · 1.08 KB
/
kontrollflerefiler.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
#!/bin/bash
# Statuskoder
# 0 -> fil eksisterer ikke
# 1 -> fil eksisterer
i=0
echo -n "Overvåker følgende filer: "
for arg
do
echo -n "$arg "
status[$i]=0
i=$((i+1))
done
echo
status=
file_time=
i=0
for arg
do
if [ -f $arg ]
then
echo "Filen $arg eksisterer allerede."
status[$i]=1
file_time[$i]=$(stat -f "%m" $arg)
else
echo "Filen $arg eksisterer ikke."
status[$i]=0
file_time[$i]=-1
fi
i=$((i+1))
done
while true
do
i=0
for arg
do
#echo "$i $arg ${status[$i]} ${file_time[$i]}"
if [ -f $arg ] && [ "${status[$i]}" == 0 ]
then
echo "Filen $arg ble opprettet."
file_time[$i]=$(stat -f "%m" $arg)
status[$i]=1
i=$((i+1))
continue
fi
if [ ! -f $arg ] && [ ${status[$i]} == 1 ]
then
echo "Filen $arg ble slettet."
file_time[$i]=-1
status[$i]=0
i=$((i+1))
continue
fi
if [ ${status[$i]} = 1 ] && [ "${file_time[$i]}" != "$(stat -f "%m" $arg)" ]
then
echo "Filen $arg ble endret."
file_time[$i]=$(stat -f "%m" $arg)
status[$i]=1
i=$((i+1))
continue
fi
i=$((i+1))
done
sleep 60
done