linux使用命令链接设备,linux – 通过USB连接设备时执行命令

Rule files are stored in the /etc/udev/rules.d/ directory.

There’s some advice from the README in that directory on how to name

rule files:

Files should be named xx-descriptive-name.rules, the xx should be

chosen first according to the following sequence points:

< 60 most user rules; if you want to prevent an assignment being

overriden by default rules, use the := operator.

these cannot access persistent information such as that from vol_id

< 70 rules that run helpers such as vol_id to populate the udev db

< 90 rules that run other programs (often using information in the

udev db)

=90 rules that should run last

udev规则的第一部分是匹配键.我们将使用

KERNEL从链的最顶端进入以及idVendor,

idProduct,以及来自设备特定信息的串行属性.

这将肯定地识别这个特定的拇指驱动器并忽略

所有其他人.内核参数使用问号作为通配符

如果我们的驱动器安装在不同的节点上(即:sda1,sdb1,

sdc1等)它仍然可以被识别出来.

KERNEL=="sd?1", ATTRS{idVendor}=="13fe", ATTRS{idProduct}=="1f00",

ATTRS{serial}=="50E6920B000AE8"

Now that we have the keys necessary to

identify the particular hardware we’re looking for we can add

assignment arguments. In our case we added two. The first creates a

symlink to this device inside of the /dev/ directory. The second

executes a script in our home directory:

SYMLINK+="hackaday", RUN+="/home/mike/notify-plugin.sh 'HackaDay Thumbdrive:' 'Connected as: $KERNEL'"

Here is the final rule assembled

into one line:

KERNEL=="sd?1", ATTRS{idVendor}=="13fe", ATTRS{idProduct}=="1f00", ATTRS{serial}=="50E6920B000AE8", SYMLINK+="hackaday", RUN+="/home/mike/notify-plugin.sh 'HackaDay Thumbdrive:' 'Connected as: $KERNEL'"

We added this as the only line in our rule file and then

restarted udev using these commands:

sudo nano /etc/udev/rules.d/81-thumbdrive.rules

sudo /etc/init.d/udev restart

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值