操作系统MacOS 10.15.17 (Catalina)
我想创建一个脚本,该脚本使用iperf启动一个客户端,该客户端每隔几秒测量一次连接速度并持续很长一段时间。我创建了一个守护程序文件并将其放入~/Library/LaunchAgents/com.myself.iperfclient.plist
.
com.myself.iperfclient.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>com.myself.iperfclient</string>
<key>ProgramArguments</key>
<array>
<string>/Users/myself/Documents/bin/iperf/netspeed</string>
</array>
<key>StartInterval</key>
<integer>20</integer> <!-- in seconds -->
<key>Disabled</key>
<false/>
</dict>
</plist>
网速
#!/bin/bash
# see https://stackoverflow.com/a/246128/10200417
script_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
script_name=`basename $0`
# echo "called script $script_name from $script_dir"
iperf_server=127.0.0.1
iperf_port=54321
# launch iperf client, log results to ./logs/client.log
iperf \
-c $iperf_server \
-p $iperf_port \
--logfile $script_dir/logs/client.log
该netspeed
文件对任何人都是可执行的:
$ ls -l netspeed
-rwxr-xr-x@ 1 myself staff 379 Jan 11 21:36 netspeed
当我尝试添加新的守护程序时,使用launchctl load ~/Library/LaunchAgents/com.myself.iperfclient.plist
,这是我在控制台中收到的错误消息:
Sandbox: bash(50654) System Policy: deny(1) file-read-data /Users/myself/Documents/bin/iperf/netspeed
如果在我添加为第一项.plist
的守护程序描述符中,则没有错误。但是,我不想以这种方式运行脚本,因为它每次都会启动一个新的终端窗口,这非常烦人。<string>open</string>
ProgramArguments
我的问题
如何允许我的守护进程执行netspeed
?
附言
launchctl 状态码是126。
$ launchctl list | grep myself
- 126 com.myself.iperfclient