从我的launchd作业收到错误代码126



我正在尝试了解更多关于launchd的信息,以及如何使用它来自动化一些任务。出于某种原因,当我的非常简单的示例作业运行时,它会退出,状态代码为126。我已经更改了所有文件的权限,以确保我不是问题所在(因为126个代码通常与权限有关(,但问题仍然存在。

/Library/LaunchDaemon/test.plst

<?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>test.monday</string>
<key>Program</key>
<string>/Users/philliptroutman/Desktop/test.sh</string>
<key>RunAtLoad</key>
<true/>
<key>StartInterval</key>
<integer>20</integer>
</dict>
</plist>

/用户/philiptroutman/Desktop/test.sh

#! /bin/sh
echo 'some data' >> /Users/philliptroutman/Desktop/examplefile.txt
echo "some random echo!"

在我加载和卸载plst文件后,这就是我得到的

launchctl unload /Library/LaunchDaemons/test.plist
launchctl load /Library/LaunchDaemons/test.plist
launchctl list | grep test.monday
-   126 test.monday

我想我的问题很简单。。。为什么不起作用?

我在从~/Documents/scpts文件夹执行launchd plist时遇到了同样的问题。奇怪的是,它们在Google Drive文件夹中运行良好,文档链接到该文件夹,但在只有我的常规~/Documents/脚本的机器上,它们会失败,并出现错误126。苹果公司已将~/Documents Desktop和Downloads指定为私人目录。Launchd无法从中执行脚本。

将脚本移动到不同的目录,如~/Library/scripts您可以随时将它们软链接回您希望找到它们的位置。

我在launchd plists上也遇到了同样的问题。与Matthew所说的不同,我的解决方案是使用/usr/local/bin/bash来调用脚本,而不是使用/bin/bash/bin/sh/usr/local是由自制软件安装的。这意外地解决了我的问题。

相关内容

最新更新