Re: Resetting a USB port in Debian 10
On Thu, 2022-05-19 at 07:00 -0400, Greg Wooledge wrote:
> On Thu, May 19, 2022 at 08:54:52AM +0100, Tixy wrote:
> > To find the device ID my bash script scans the USB serial numbers
> > looking for the one I'm interested in...
> >
> > pushd /sys/bus/usb/drivers/usb >/dev/null
> > for f in **/serial
> > do
> > if [ "$(cat $f)" = MY_SERIAL_NUMBER ]; then
> > ID=${f%%/*}
> > fi
> > done
> > popd >/dev/null
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > if [ "$ID" = "" ]; then
> > echo "Can't find device"
> > exit 1
> > fi
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > There's no doubt better ways of doing the above, but it works for me.
> > (Looking at it now I'd get rid of the pushd/popd by using an extra
> > string splice operation and that use of ** probably needs something
> > doing to it to cope with spaces in paths)
>
> 1) For ** to work, you need to do "shopt -s globstar" somewhere before it.
I didn't know that, it works for me without setting that option.
$ shopt | grep globstar
globstar off
$ echo /sys/bus/usb/drivers/usb/**/serial
/sys/bus/usb/drivers/usb/usb1/serial
/sys/bus/usb/drivers/usb/usb2/serial
/sys/bus/usb/drivers/usb/usb3/serial
/sys/bus/usb/drivers/usb/usb4/serial
$ shopt -s globstar
$ shopt | grep globstar
globstar on
$ echo /sys/bus/usb/drivers/usb/**/serial
/sys/bus/usb/drivers/usb/usb1/serial
/sys/bus/usb/drivers/usb/usb2/serial
/sys/bus/usb/drivers/usb/usb3/serial
/sys/bus/usb/drivers/usb/usb4/serial
--
Tixy
Reply to: