新贵调用脚本(插入的USB驱动器) [英] Upstart calling script (for inserted USB-drive)

查看:117
本文介绍了新贵调用脚本(插入的USB驱动器)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,Ubuntu的(和Fedora)使用暴发户经典的System V的init守护进程(的SysVinit)的istead

I know that Ubuntu (and Fedora) uses Upstart istead of the classical System V init daemon (SysVinit).

我想知道当一个USB驱动器已插入如何检测,安装它和一些文件复制到其中。我想新贵打电话给我自己的这个脚本。

I would like to know how to detect when a USB-drive has been inserted, mount it and copy some files to it. I would like Upstart to call my own script for this.

如果有可能,我想新贵调用脚本,针对一的具体的USB驱动器,这样我就为除了我的即时备份USB驱动器的每个USB驱动器得到正常功能

If it is possible I would like Upstart to call the script for a specific USB-drive, so that I would get normal functionality for every USB-drive except my "instant backup" USB-drive.

如果新贵能送USB驱动器识别字符串作为参数传递给我的剧本我想这将是理想的解决方案,因为我能有ID字符串在我的剧本,可能可以使脚本处理两个USB -drives没有太大的变化。

If Upstart could send the USB-drive identification string as an argument to my script I guess that would be the ideal solution, as I would be able to have the id string in my script and possibly could make the script handle two USB-drives without much change.

而作为一个侧面说明,你知道,除了新贵任何其他系统,该系统处理的USB驱动器,网络安装的文件系统,并在这样的一个不错的方式? (由于的SysVinit似乎没有的。)

And as a side-note, do you know any other system except Upstart which handles USB-drives, network mounted file systems and such in a nice way? (As SysVinit seems not to.)

推荐答案

新贵似乎并不附带信号开箱即用插入USB设备。重点迄今已做pretty究竟多INIT同样的事情,而酷标榜的功能是在未来。

upstart doesn't seem to come with "usb device plugged in" signals out of the box. The focus so far has been to do pretty much exactly the same thing as init, and the "cool advertised features" are in the future.

从Fedora维基:......让自己暴发户的地方,现在,即使它只会充当的SysV现在这样,让我们​​开始朝这一模式的平稳过渡。

From the Fedora wiki: "...getting Upstart itself in place now, even though it will only be functioning as SysV does now, will allow us to begin a smooth transition toward this model."

幸运的是,你可以通过让udev的运行脚本来发送自定义信号新贵暴发户这样可以调用您的备份脚本实现自己的未来。您还可以让udev的直接调用你的备份脚本。

Luckily, you can implement the future yourself by having udev run a script to send your custom upstart signal so upstart can call your backup script. You could also have udev call your backup script directly.

的udev 已经有一个简单的方法,当设备插拔运行脚本。见<一href=\"http://web.archive.org/web/20090210121543/http://linuxconfig.org/Override_/_rename_your_usb_hard_drive%27s_device_name_with_udev_rules\"相对=nofollow>与udev规则的重命名您的USB硬盘驱动器的设备名称。在我的系统,我将不得不使用 udevadm监控--env 而不是本教程的 udevmonitor --env 。继教程后,您将创建这样彼此udev规则:

udev already has a simple way to run scripts when devices are plugged and unplugged. See rename your usb hard drive's device name with udev rules. On my system, I would have to use udevadm monitor --env instead of the tutorial's udevmonitor --env. After following the tutorial, you would create another udev rule like this one:

echo 'SUBSYSTEM=="block", ID_SERIAL_SHORT=="101A9041C67D182E", \
NAME="myusbdrive", \
RUN+="/my/backup/script $env{NAME}"' > /etc/udev/rules.d/S96-mydrive.rules

更换 ID_SERIAL_SHORT 与设备的实际ID,而 $ ENV {NAME} 与任何udev的环境变量(S )你的脚本需要找到备份设备。您可能需要后台脚本来避免阻塞的udev。

Replacing ID_SERIAL_SHORT with your device's actual id, and $env{NAME} with whatever udev environment variable(s) your script needs to find the backup device. You might need to background the script to avoid blocking udev.

如果你想使用的暴发户,你可以有你的udev规则运行 / sbin目录/ EMIT initctl的背它向上变= $ ENV {}变量... 然后写在 /etc/event.d 与线开始的脚本开始回溯它向上

If you want to use upstart, you could have your udev rule run /sbin/initctl emit back-it-up VARIABLE=$env{VARIABLE} ... and then write a script in /etc/event.d beginning with the line start on back-it-up.

又见<一个href=\"http://stackoverflow.com/questions/469243/how-can-i-listen-for-usb-device-inserted-events-in-linux-in-python\">How我可以听在Linux中的事件,在Python中插入的USB设备?的,用于提示做同样用的的DBus 。如果你想有登录的用户运行一个用户模式监视备份驱动器的DBus可能会更方便守护进程。

See also How can I listen for 'usb device inserted' events in Linux, in Python? for hints on doing the same with DBus. DBus might be more convenient if you want to have the logged in user run a usermode "watch for backup drive" daemon.

这篇关于新贵调用脚本(插入的USB驱动器)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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