【发布时间】:2016-02-12 15:55:27
【问题描述】:
我最初想在我的 PC 中插入 USB 记忆棒时运行一个脚本,然后在删除它时运行另一个脚本,我与 udev 搞混了,但没有任何成功,所以这显然不是最好的选择,我然后遇到了 inotifywait ,我可以在我的驱动器安装时查看一个文件夹,因为这会给我我正在寻找的 CREATE,ISDIR myfolder 输出,但是使用它来实际触发外部脚本有点超出我的编程技能,我看过 EXPECT 但看不到我将如何完成我的任务,我想基本上我需要创建一个遵循如下所示流程的期望脚本
Expect spawns the inotifywait process
expect then starts a loop
if the loop sees "CREATE,ISDIR test" then run script active.sh
if the loop sees "DELETE,ISDIR test" then run scrip inactive.sh
Loop
可能有一种更简单的方法可以做到这一点,但我到处搜索并尝试了各种不同的组合,简而言之,我希望在创建某个文件夹时运行一个脚本,然后在删除它时运行另一个脚本,有没有一种简单的方法可以做到这一点?
【问题讨论】:
标签: linux expect udev inotifywait