5 |
|
|
6 |
while true |
while true |
7 |
do |
do |
8 |
ALLCLIENTS=$(mysqldo "select id from clients") |
ALLCLIENTS=$(mysqldo "select ip from clients") |
9 |
|
|
10 |
for client in ${ALLCLIENTS} |
for client in ${ALLCLIENTS} |
11 |
do |
do |
12 |
clientip=$(mysqldo "select ip from clients where id='${client}'") |
# filter all not connected clients |
13 |
|
if [[ $(mysqldo "select connected from clients where ip='${client}'") = 1 ]] |
|
if [[ $(mysqldo "select connected from clients where id='${client}'") = 1 ]] |
|
14 |
then |
then |
15 |
BUSID=$(mysqldo "select busid from clients where id='${client}'") |
BUSID=$(mysqldo "select busid from clients where ip='${client}'") |
16 |
|
|
17 |
echo "-- polling client #${client} - ${clientip} on dev ${BUSID}" |
echo "-- polling client #${client} on dev ${BUSID}" |
18 |
usbip -a ${clientip} ${BUSID} |
usbip -a ${client} ${BUSID} |
19 |
else |
else |
20 |
echo "-- client #${client} - ${clientip} not found, removing from list" |
echo "-- client #${client} not found, removing from list" |
21 |
|
|
22 |
out=$(mktemp) |
out=$(mktemp) |
23 |
port=$(usbip -p &> ${out};grep -B3 -i "${clientip}" ${out} | grep Port | cut -d' ' -f2| sed "s|:||") |
port=$(usbip -p &> ${out};grep -B3 -i "${client}" ${out} | grep Port | cut -d' ' -f2| sed "s|:||") |
24 |
[[ ! -z ${port} ]] && usbip -d ${port} |
[[ ! -z ${port} ]] && usbip -d ${port} |
25 |
#mysqldo "delete from client where id='${client}'" |
|
26 |
|
mysqldo "update clients set connected='0', busid='' where ip='${client}'" |
27 |
fi |
fi |
28 |
|
|
|
sleep ${USBIP_WAIT_TIMEOUT} |
|
29 |
done |
done |
30 |
|
|
31 |
|
sleep ${USBIP_WAIT_TIMEOUT} |
32 |
done |
done |