How to reset USB port remotely

Розділи: 


#!/bin/bash
usb=`dmesg | grep "New USB device found, idVendor=1058, idProduct=0820"|cut -f1 -d':'| awk '{print $4}' | tail -1`
sudo sh -c "echo $usb > /sys/bus/usb/drivers/usb/unbind"
sudo sh -c "echo $usb > /sys/bus/usb/drivers/usb/bind"

Замінюйте параметри grep на те що вам потрібно.
В моєму випадку результат має бути ось такий:

# dmesg | grep "New USB device found, idVendor=1058, idProduct=0820"|cut -f1 -d':'| awk '{print $4}' | tail -1

1-6

В syslog все виглядає ніби я витягнув флешку і вставив назад:

Jan 29 11:42:33 backupoff kernel: [213784.547395] ses 4:0:0:1: Attached Enclosure device
Jan 29 11:42:33 backupoff kernel: [213784.547416] sd 4:0:0:0: [sdc] 3906963456 512-byte logical blocks: (2.00 TB/1.82 TiB)
Jan 29 11:42:33 backupoff kernel: [213784.547653] sd 4:0:0:0: [sdc] Write Protect is off
Jan 29 11:42:33 backupoff kernel: [213784.547655] sd 4:0:0:0: [sdc] Mode Sense: 47 00 10 08
Jan 29 11:42:33 backupoff kernel: [213784.548068] sd 4:0:0:0: [sdc] No Caching mode page found
Jan 29 11:42:33 backupoff kernel: [213784.548106] sd 4:0:0:0: [sdc] Assuming drive cache: write through
Jan 29 11:42:38 backupoff kernel: [213789.802794] sdc: sdc1
Jan 29 11:42:38 backupoff kernel: [213789.804556] sd 4:0:0:0: [sdc] Attached SCSI disk
Jan 29 11:42:38 backupoff kernel: [213789.805101] ses 4:0:0:1: Attached scsi generic sg3 type 13