macos - /bin/zsh 在 launchd 运行时无法打开脚本
问题描述
我有一个非常简单的 zsh 脚本,我想使用 launchd 定期运行它。我决定使用 LaunchDaemons,因为它看起来更通用。我相信这个过程开始了,因为路径中有输出,在StandardErrorPath
plist 文件的键中定义。
脚本如下所示:
#!/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
我尝试了什么:
- 将 plist 所有者从我的用户更改为 LaunchDaemons 文件夹中的 root 使用
sudo chown root testplist.plist
- 使用 zsh 脚本制作可执行文件
chmod +x filename
- 运行脚本本身,成功 (
/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>
解决方案
推荐阅读
- kubernetes - 设置 ClusterIp 时不暴露 Kubernetes 服务
- amazon-web-services - 生成策略和签名值以将数据直接从 HTML 发布请求存储到 Amazon S3 存储桶
- c# - ASP.NET Core 2.0 Razor Pages Web 应用单独的复杂 BindProperty 表单
- laravel - 如何在浏览器中查看文件 pdf 而无需在 laravel 5.6 中下载
- python - 从用户定义的字符串动态添加@property到python类
- android - 使用 Intent 将多张图片发布到 Instagram
- java - 已选择单选按钮
- r - 对多组列求和
- java - 我可以在没有复选框的情况下在浏览器重新启动后使用 spring Remember-me 来恢复浏览器会话吗
- java - LibGDX 使视口大于屏幕