-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlisten.sh
executable file
·60 lines (52 loc) · 1.55 KB
/
listen.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
#!/bin/bash
set -e
if [ $# -lt 2 -o $# -gt 3 ]; then
echo "Usage: $0 monitor stream-name [auto-connect-pattern]"
echo ""
echo "monitor: the binary of the monitor to execute"
echo "stream-name: the name of the stream to connect to"
echo "auto-connect-pattern: if the SHM buffer matches this pattern, do not ask whether to connect, do it!"
exit 1
fi
MON=$1
STREAM=$2
AUTOCONN="$3"
while true; do
echo -e "\033[33mWaiting for a new connection...\033[0m"
if [ ! -z "$AUTOCONN" ]; then
echo -e "\033[33m(autoconnecting to '$AUTOCONN')\033[0m"
fi
# does not work for some reason...
# inotifywait -q "/dev/shm" -e create --exclude='.*\.ctrl' | read dir action file
rm -f .evs.txt
inotifywait -q "/dev/shm" -e create --exclude='.*\.ctrl' --outfile .evs.txt
read dir action file <<< $(cat .evs.txt)
SHM="/$file"
HAVE_GREEN="no"
if [ ! -z "$AUTOCONN" ]; then
if echo "$SHM" | grep -q "$AUTOCONN" ; then
echo -e "\033[32mAutoconnecting to $SHM\033[0m"
HAVE_GREEN="yes"
else
echo -e "\033[33mSkipping autoconnect to $SHM\033[0m"
fi
else
while true; do
read -p "Do you want to connect to '$file' [Y/n]? " answer
if [ -z "$answer" -o "$answer" == "y" -o "$answer" == "Y" ]; then
HAVE_GREEN="yes"
break
elif [ "$answer" == "n" ]; then
echo "Very well, skipping..."
break
else
echo "Invalid answer, try again!"
fi
done
fi
if [ "$HAVE_GREEN" == "yes" ]; then
echo "Command: " $MON $STREAM:generic:"/$file"
time $MON "$STREAM:generic:$SHM" ||
echo -e "\033[31;1m*** Failed running monitor! ***\033[0m"
fi
done