在RPi上插入USB后,使用udev运行脚本 [英] Run script with udev after USB plugged in on RPi

查看:66
本文介绍了在RPi上插入USB后,使用udev运行脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

插入USB驱动器后,我试图根据udev规则运行脚本.

I am trying to run a script from a udev rule after any USB drive has been plugged in.

当我手动运行脚本时,在正常安装USB后,它将运行良好.该脚本调用python程序来运行,并且python程序使用USB驱动器上的文件.那里没有问题.如果我使脚本仅将日期记录在文件中,则效果很好.因此,我知道我的UDEV规则和脚本可以很好地工作,它们各自独立.

When I run the script manually, after the USB is mounted normally, it will run fine. The script calls a python program to run and the python program uses a file on the USB drive. No issues there. If I make the script to simply log the date in a file, that works just fine. So I know my UDEV rule and my script work fine, each on their own.

当udev调用脚本,然后脚本调用python程序并且python程序无法正常运行时,似乎出现了问题.我相信是在python脚本运行之前USB驱动器尚未完成安装.当观看顶部时,我的脚本开始运行,然后python开始运行,它们都结束了,然后出现访问USB驱动器上的文件的窗口弹出窗口.

The issue seems to come up when udev calls the script, then script calling the python program and the python program does not run right. I believe it to be that the USB drive has not finished mounting before the python script runs. When watching top, my script begins to run, then python begins to run, they both end, and then I get the window popup of my accessing the files on my USB drive.

所以我尝试让script1.sh调用script2.sh调用python.py.我尝试让script.sh调用python1.py调用python2.py.我尝试在script.sh和python.py中都添加睡眠功能.我尝试了RUN + ="/home/pi/script.sh& exit"规则.我尝试在文件中退出.我尝试不显示在文件中.

So I tried having script1.sh call script2.sh call python.py. I tried having script.sh call python1.py call python2.py. I tried adding sleep function both in the script.sh and python.py. I tried in the rule, RUN+="/home/pi/script.sh & exit". I tried exit in the files. I tried disown in the files.

我还能尝试什么?

推荐答案

您可能描述过您的问题.挂载过程太慢.您可以从 script.sh

Well you probably described you problem. The mount process is too slow. You can mount your usb device from your script.sh

此外,您可能只需要为系统或特定设备禁用自动USB设备安装.

Also you probably need to disable automatic USB device mount for your system or the specific device only.

如果您向udev规则添加符号链接,例如 SYMLINK + =备份" ,然后可以通过以下方式安装此设备:

If you add a symlink to your udev rule e.g. SYMLINK+="backup", then you can mount this device by:

mkdir -p/path/to/foomount -t ext4/dev/backup/path/to/foo

这篇关于在RPi上插入USB后,使用udev运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆