-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmonitor.sh
executable file
·56 lines (46 loc) · 1.05 KB
/
monitor.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
#!/bin/sh
filename="monitor.log"
maxsize=14500
csvfile="kindle_vocab.csv"
kindledb="/Volumes/Kindle/system/vocabulary/vocab.db"
api_key="API_KEY"
if [ ! -f "$filename" ]
then
touch "$filename"
else
:
fi
while true
do
filesize=$(ls -l "$filename" | awk '{print $5}')
if ls /Volumes/ | grep -q Kindle
then
if [ $filesize -ge $maxsize ]
then
echo "[$(date)] Kindle connected, creating CSV file" > monitor.log
echo "[$(date)] CSV created. Waiting for disconnect..." > monitor.log
else
echo "[$(date)] Kindle connected, creating CSV file" >> monitor.log
echo "[$(date)] CSV created. Waiting for disconnect..." >> monitor.log
fi
python main.py $csvfile $kindledb $api_key
while true
do
if ! ls /Volumes/ | grep -q Kindle
then
break
else
:
sleep 5
fi
done
else
if [ $filesize -ge $maxsize ]
then
echo "[$(date)] Kindle not connected" > monitor.log
else
echo "[$(date)] Kindle not connected" >> monitor.log
fi
fi
sleep 5
done