Features:
USB Type-C PD Chargers
USB Type-A Chargers
Multi-Port USB Chargers
Integration-Ready Charging PCBAs
A 20-line Bash script that notices when a USB device drops off the bus and power-cycles its port on a Coolgear Managed USB Hub so the device comes back without anyone unplugging a cable.
Any USB peripheral that sometimes drops off the bus or hangs and recovers after a power cycle:
Requires a Coolgear Managed USB Hub with software-controlled ports, a Linux host with lsusb, and the Coolgear command-line utility (cusbi).
lsusb lists connected devices; the script looks for “Western Digital”.
If the device is listed, print “Device detected.” and exit.
If it’s missing, the hub cuts power to port 2.
The device fully powers down and resets its state.
Power returns, and Linux re-enumerates the device.
Choose a scenario to step through the lines that run and see what the terminal prints. Hover over (or tap) the underlined commands to see what they do.
lsusb lists every USB device Linux can currently see, one line per device, for example:
Bus 002 Device 004: ID 1058:25a3 Western Digital ...
grep -qi "$DEVICE" searches that list for “Western Digital”.
Match → then branch (device OK).
No match → else branch (reset the port).
With the variables filled in, this runs:
./cusbi /S:ttyUSB0 0:2
/dev/ttyUSB00 (off) for port 2Power to port 2 is cut, so the device fully shuts down. The hub’s other ports are not affected.
With the variables filled in, this runs:
./cusbi /S:ttyUSB0 1:2
/dev/ttyUSB01 (on) for port 2Power returns to port 2. The device boots, and Linux detects it again as if it had just been plugged in.
/dev/ttyUSB0
PORT="2", where the watched drive is plugged in. Only that port is power-cycled.| Variable | Value | What it does |
|---|---|---|
TOOL |
./cusbi |
Path to the Coolgear command-line utility that switches hub ports. |
CONTROL_PORT |
ttyUSB0 |
The hub’s control port, /dev/ttyUSB0, which tells the utility which managed hub to talk to. Run ls /dev/ttyUSB* to find yours. |
PORT |
2 |
The hub port the watched device is plugged into. |
DEVICE |
Western Digital |
Any text from the device’s lsusb line. The match is case-insensitive, so “western digital” also works. |
The utility’s command format is cusbi /S:<control port> <state>:<port>, where state 0 turns the port off and 1 turns it on.
* * * * * /opt/coolgear/USB_Watchdog.sh
while true; do
./USB_Watchdog.sh
sleep 30
done
DEVICE="Camera" to any text from its lsusb line.PORT="3".sleep 5 to sleep 10.Advanced_Watchdog_with_port_detection.sh finds the device’s port from lsusb -v, remembers it, and checks that recovery worked.Before deploying on Linux: keep #!/bin/bash as the first line so cron runs the script with Bash, and make it executable with chmod +x USB_Watchdog.sh (the cusbi utility needs execute permission too). Your user also needs access to /dev/ttyUSB0, usually through the dialout group.
Explore More. Automate More.
Discover more powerful automation scripts or explore Coolgear’s lineup of compatible Managed USB Hubs to expand your USB control capabilities.