简体   繁体   English

在RPi上插入USB后,使用udev运行脚本

[英]Run script with udev after USB plugged in on RPi

I am trying to run a script from a udev rule after any USB drive has been plugged in. 插入任何USB驱动器后,我试图根据udev规则运行脚本。

When I run the script manually, after the USB is mounted normally, it will run fine. 当我手动运行脚本时,在正常安装USB后,它将运行良好。 The script calls a python program to run and the python program uses a file on the USB drive. 该脚本调用一个python程序来运行,并且python程序使用USB驱动器上的一个文件。 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规则和脚本可以很好地工作,它们各自独立。

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. 当udev调用脚本,然后脚本调用python程序,而python程序无法正常运行时,似乎出现了问题。 I believe it to be that the USB drive has not finished mounting before the python script runs. 我认为这是因为python脚本运行之前USB驱动器尚未完成安装。 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. 当观看顶部时,我的脚本开始运行,然后python开始运行,它们都结束了,然后出现访问USB驱动器上的文件的窗口弹出窗口。

So I tried having script1.sh call script2.sh call python.py. 所以我尝试让script1.sh调用script2.sh调用python.py。 I tried having script.sh call python1.py call python2.py. 我尝试让script.sh调用python1.py调用python2.py。 I tried adding sleep function both in the script.sh and python.py. 我尝试在script.sh和python.py中都添加睡眠功能。 I tried in the rule, RUN+="/home/pi/script.sh & exit". 我尝试了RUN + =“ / home / pi / script.sh&exit”规则。 I tried exit in the files. 我尝试在文件中退出。 I tried disown in the files. 我尝试不显示在文件中。

What else can I try? 我还能尝试什么?

Well you probably described you problem. 好吧,您可能描述了您的问题。 The mount process is too slow. 挂载过程太慢。 You can mount your usb device from your script.sh 您可以从script.sh挂载USB设备

Also you probably need to disable automatic USB device mount for your system or the specific device only. 另外,您可能只需要为系统或特定设备禁用自动USB设备安装。

If you add a symlink to your udev rule eg SYMLINK+="backup" , then you can mount this device by: 如果将符号链接添加到udev规则,例如SYMLINK+="backup" ,则可以通过以下方式安装此设备:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM