#!/bin/bash source /etc/conf.d/usbippolld source /usr/lib/alxconfig-ng/functions/mysqlfunctions while true do ALLCLIENTS=$(mysqldo "select id from clients") for client in ${ALLCLIENTS} do clientip=$(mysqldo "select ip from clients where id='${client}'") if [[ $(mysqldo "select connected from clients where id='${client}'") = 1 ]] then BUSID=$(mysqldo "select busid from clients where id='${client}'") echo "-- polling client #${client} - ${clientip} on dev ${BUSID}" usbip -a ${clientip} ${BUSID} else echo "-- client #${client} - ${clientip} not found, removing from list" out=$(mktemp) port=$(usbip -p &> ${out};grep -B3 -i "${clientip}" ${out} | grep Port | cut -d' ' -f2| sed "s|:||") [[ ! -z ${port} ]] && usbip -d ${port} #mysqldo "delete from client where id='${client}'" fi sleep ${USBIP_WAIT_TIMEOUT} done done