Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash OS X LaunchAgent监视路径不工作,具有PID且没有错误消息_Bash_Plist_Osx Mountain Lion_Launchd - Fatal编程技术网

Bash OS X LaunchAgent监视路径不工作,具有PID且没有错误消息

Bash OS X LaunchAgent监视路径不工作,具有PID且没有错误消息,bash,plist,osx-mountain-lion,launchd,Bash,Plist,Osx Mountain Lion,Launchd,我编写了一个小型LaunchAgent来监视文件夹的更改,并在发生更改时触发一个shell脚本: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd > <plist version="1.0"> &l

我编写了一个小型LaunchAgent来监视文件夹的更改,并在发生更改时触发一个shell脚本:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN
           http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.myusername.w2</string>
    <key>ProgramArguments</key>
    <array>
    <string>/Users/myusername/Desktop/alert</string>
    </array>
    <key>WatchPaths</key>
    <array>
        <string>/Users/myusername/Personnel</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>WorkingDirectory</key>
    <string>/Users/myusername</string>
    <key>StandardErrorPath</key>
    <string>myjob.log</string>
    <key>StandardOutPath</key>
    <string>myjob.log</string>
    <key>Debug</key>
    <true/>
    <key>WaitForDebugger</key>
    <true/>

</dict>
</plist>
文件名与标签相同 我使用Launchctl加载并启动代理 我注销/登录了我的会话 我使用Launchctl列表进行检查,代理具有正确的PID,状态代码为0 我所有的网址都是绝对的 尽管如此,它并没有像预期的那样工作:我在关注的文件夹中添加了一个文件,脚本没有被触发

日志文件已创建但为空无错误

如果有人能指出正确的方向,那就太棒了。

有两件事需要检查:

取下WaitForDebugger钥匙。至少,移除它可以让我做一个有效的测试。显然,它是有目的的,但我不能建议如何将调试器附加到进程

确保/Users/myusername/Desktop/alert是可执行的chmod+x/Users/myusername/Desktop/alert

由于RunAtLoad选项设置为true,因此在登录后立即启动脚本。您的意思是在launchctl列表输出中看到一个PID。这意味着对于启动,代理已在运行,无需再次运行


我建议删除RunAtLoad键或使/Users/myusername/Desktop/alert脚本快速退出。您将在launchctl列表输出的PID列中看到-符号。

Is/Users/myusername/Desktop/alert您要运行的脚本?@chepner是的,它是脚本