首页 > 解决方案 > /bin/zsh 在 launchd 运行时无法打开脚本

问题描述

我有一个非常简单的 zsh 脚本,我想使用 launchd 定期运行它。我决定使用 LaunchDaemons,因为它看起来更通用。我相信这个过程开始了,因为路径中有输出,在StandardErrorPathplist 文件的键中定义。

脚本如下所示:

#!/bin/zsh
echo "hello"

plist 文件如下所示:

列表条目

当我使用加载launchd过程时

launchctl load /Library/LaunchDaemons/testplist.plist

没有错误消息,但在 system.log 中每次尝试执行时都会出现错误消息。它有所不同,但我一直得到一个错误:

服务退出异常代码:127

此外,每次在系统日志中添加错误 127 时,也会在 plist 中指定的文件中添加一行StandardErrorPath. 这条线是

/bin/zsh:无法打开输入文件:/Users/username/Downloads/zsh/test.zsh

我尝试了什么:

最后一件事,可能相关也可能不相关,当我编写我的 zsh 脚本时,我将权限更改为 750,因为这是教程所说的,没有它就不会运行。

plist的文本格式:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>testplist</string>
    <key>RunAtLoad</key>
    <true/>
    <key>StartInterval</key>
    <integer>20</integer>
    <key>StandardErrorPath</key>
    <string>/Users/username/Downloads/zsh/stderr.log</string>
    <key>StandardOutPath</key>
    <string>/Users/username/Downloads/zsh/stdout.log</string>
    <key>Program</key>
    <string>/Users/username/Downloads/zsh/test.zsh</string>
    <key>KeepAlive</key>
    <true/>
    <key>Debug</key>
    <true/>
</dict>
</plist>

标签: macoszshlaunchd

解决方案


推荐阅读