-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathglob_and_watch.sh
More file actions
executable file
·46 lines (36 loc) · 961 Bytes
/
Copy pathglob_and_watch.sh
File metadata and controls
executable file
·46 lines (36 loc) · 961 Bytes
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
#!/bin/bash
cleanup() {
echo "Cleaning up..."
kill $pid1 $pid2 2>/dev/null
}
trap cleanup INT TERM EXIT
DIR="$( cd "$(dirname "$0")" ; pwd -P )"
cd $DIR
TARGET=./raw
function doglob() {
echo "ts,bytes,path,events"
cd $DIR
find $TARGET -type f | while read -r file; do
ts_and_bytes=$(stat -c "%y,%s" "$file")
echo "$ts_and_bytes,$file,glob"
done
}
function dowatch() {
echo "ts,bytes,path,events"
# WARNING: might need "%w%f" to protect spaces
inotifywait -mrq --timefmt '%Y-%m-%dT%H:%M:%S' --format '%T %w%f %|e' -e close_write,moved_to,moved_from,move_self,create,delete,delete_self,unmount $TARGET | \
while read -r ts path events; do
bytes=$(stat -c "%s" $path)
echo "$ts,$bytes,$path,$events"
done
}
doglob > glob.csv 2> glob.err &
pid1=$!
dowatch > watch.csv 2> watch.err &
pid2=$!
wait $pid1
wait $pid2
trap - INT TERM EXIT
echo $pid1
echo $pid2
echo should be stopped