ubuntu下不用拔盘就可以重新识别usb设备

#!/bin/sh
# Usage: ./resetusb ARGUMENT(The keyword for your usb device)
var1
=$1 keyword=${var1:=Storage} debug=$(lsusb) bus=$(lsusb|grep $keyword|perl -nE "/\D+(\d+)\D+(\d+).+/; print qq(\$1)") device=$(lsusb|grep $keyword|perl -nE "/\D+(\d+)\D+(\d+).+/; print qq(\$2)") echo "/* usbreset -- send a USB port reset to a USB device */ #include <stdio.h> #include <unistd.h> #include <fcntl.h> #include <errno.h> #include <sys/ioctl.h> #include <linux/usbdevice_fs.h> int main(int argc, char **argv) { const char *filename; int fd; int rc; if (argc != 2) { return 1; } filename = argv[1]; fd = open(filename, O_WRONLY); if (fd < 0) { return 1; } rc = ioctl(fd, USBDEVFS_RESET, 0); if (rc < 0) { return 1; } close(fd); return 0; }" > /tmp/usbreset.c $(cc /tmp/usbreset.c -o /tmp/usbreset) $(chmod +x /tmp/usbreset) $(cd /tmp/;./usbreset /dev/bus/usb/$bus/$device) result=$? if [ $result != 0 ];then echo "Reset Usb Failed!" echo "Please make sure you have inputted right device keyword: $keyword" echo "You have chose bus:${bus:=Not Found},device:${device:=Not Found}" echo "More info:\n$debug" else echo "Reset Usb $keyword Successfully!" fi

 

转载于:https://www.cnblogs.com/domainfei/p/4605310.html

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值