我正在尝试更多地了解 launchd 以及如何使用它来自动执行某些任务。出于某种原因,当我的非常简单示例作业运行时,它以状态代码 126 退出。我更改了我所有文件的权限以确保我不是问题所在(因为 126 代码通常有一些事情要做具有权限),但问题仍然存在。
/图书馆/LaunchDaemons/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>
/Users/philliptroutman/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/scipts 文件夹执行的 launchd plists 我遇到了同样的问题。奇怪的是,它们在 Google Drive 文件夹中运行良好 Documents 被链接到但在只有我的常规 ~/Documents/scripts 的机器上,它们会失败并出现错误 126。Apple 已将 ~/Documents Desktop 和 Downloads 指定为私有(private)目录。 Launchd 无法从它们执行脚本。
将脚本移动到不同的目录,如 ~/Library/scripts 您始终可以将它们软链接(soft link)回您希望对它们进行罚款的任何地方。
关于ios - 从我启动的作业中收到错误代码 126,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67047816/