Skip to content

Instantly share code, notes, and snippets.

@netmaniac
Last active November 21, 2019 21:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netmaniac/bdd8aa6216d7cc8e04900b2f9c85431d to your computer and use it in GitHub Desktop.
Save netmaniac/bdd8aa6216d7cc8e04900b2f9c85431d to your computer and use it in GitHub Desktop.
Simple bash function for checking if new usb serial converter has been attached. Tested on Ubuntu 18.04. Use PATH_NAME=$(wait_for_new_usb_serial)
function wait_for_new_usb_serial() {
local array=(`ls -1 //sys/bus/usb-serial/devices/`)
local ret=""
local current_devices
while (true) do
sleep 2
current_devices=(`ls -1 //sys/bus/usb-serial/devices/`)
for value in "${current_devices[@]}"
do
if [[ ! " ${array[@]} " =~ " ${value} " ]]; then
echo "$value"
ret="x"
break
fi
done
if [[ ! "x$ret" = "x" ]]; then
break
fi
array=("${current_devices[@]}")
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment