-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdiscordcomp.sh
89 lines (78 loc) · 1.87 KB
/
discordcomp.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
80
81
82
83
84
85
86
87
#!/bin/bash
########################################
# This script needs `wc` and `seq` #
# Set DB to a custom path if you want #
# Note that this is untested #
########################################
DB=processes.txt
###########################
# Touch at your own peril #
###########################
SELFDIR=$(dirname "$(readlink -f "$0")")
TMP=/tmp/discordhelper
mkdir -p /tmp/discordhelper
rm -rf /tmp/discordhelper/*
cd $SELFDIR
PID=0
COUNT=1
function thread {
CURRENT=$1
PID=$2
DB=$3
TMP=$4
if [[ -f $TMP/$CURRENT.dummy ]]
then
echo "$CURRENT already has an instance running or thread was force closed, exiting"
exit
fi
if [[ -z $PID ]]
then
echo "vars not set, exiting"
exit
fi
cp dummy "$TMP/$CURRENT.dummy"
chmod +x "$TMP/$CURRENT.dummy"
"$TMP/$CURRENT.dummy" > /dev/null &
DUMMYPID=$!
GETCURRENTPID=$(pgrep -x "$CURRENT")
while [ true ]
do
if [[ "$(echo "$GETCURRENTPID" | grep "$PID")" == "$PID" ]]
then
sleep 5
GETCURRENTPID=$(pgrep -x "$CURRENT")
else
kill -9 $DUMMYPID
sleep 1
rm -f $TMP/$CURRENT.dummy
exit
fi
done
exit
}
while [[ true ]]
do
for i in $(seq 1 $(cat $DB | wc -l))
do
CURRENT=$(cat $DB | awk "NR == $COUNT")
PID=$(pgrep -x "$CURRENT")
pgrep -x "$CURRENT" > /dev/null 2>&1 && echo "$CURRENT is running with PID $PID"
if [[ $PID == "0" ]]
then
true
elif [[ -z "$PID" ]]
then
true
else
thread "$CURRENT" "$PID" "$DB" "$TMP" > /dev/null &
fi
COUNT=$((COUNT + 1))
if (( $COUNT > $(cat $DB | wc -l) ))
then
COUNT=1
sleep 10
fi
PID=0
sleep 1
done
done