jas*_*son 3 mac launchd plist launchctl macos
我已经阅读了 plist 和 launchd.plist 的手册页,以及有关使用 plist 文件在登录时运行脚本的帖子;但我似乎可以让事情运转起来。
我的脚本位置和权限:
sshfs_mounts.sh:
ls -al Library/scripts/
-rwxr-xr-x 1 jason staff 288 May 10 17:06 sshfs_mounts.sh
Run Code Online (Sandbox Code Playgroud)
cat Library/scripts/sshfs_mounts.sh
#!/bin/bash
#
## automounting of sshfs directories
mount_cosmic ()
{
/usr/local/bin/sshfs jason@iss.nasa.gov:/media/NetworkShare/spacedock-1 /Users/jason/share;
}
mount |grep "/Users/jason/share/"
if [ $? == 1 ] && [ -d "/Users/jason/share" ] && [ $USER == "jason" ]; then
mount_cosmic
fi
Run Code Online (Sandbox Code Playgroud)
从原始帖子编辑:
如果我手动运行脚本,它会按预期执行。我可以加载 plist ( launchctl load ~/Library/LaunchAgents/local.sshfs.plist) 并启动它 ( launchctl start ~/Library/LaunchAgents/local.sshfs),但它不运行脚本。在日志 ( cat /var/log/system.log |grep local.sshfs) 中,我得到:
May 11 09:30:26 rover com.apple.launchd.peruser.504[305] (local.sshfs.plist): Throttling respawn: Will start in 10 seconds
Run Code Online (Sandbox Code Playgroud)
这是我对 plist 文件的位置和权限:
ls -al Library/LaunchAgents/local.sshfs.plist
-rw-r--r-- 1 jason staff 419 May 10 18:14 Library/LaunchAgents/local.sshfs_mounts.plist
Run Code Online (Sandbox Code Playgroud)
和文件(在接受戈登的建议后编辑^2):
<?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>KeepAlive</key>
<true/>
<key>Label</key>
<string>local.sshfs.plist</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>/Users/jason/Library/scripts/sshfs_mounts.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/sshfs_mounts.err</string>
<key>StandardOutPath</key>
<string>/tmp/sshfs_mounts.out</string>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
马哈洛提前。
“没有返回 plist”错误意味着它无法解析 .plist 文件。我立即看到了两个问题:Lableshould beLabel和</true>should be <true/>。您可以使用该命令plutil -lint ~/Library/LaunchAgents/local.sshfs_mounts.plist检查 plist 语法,尽管它不会检测 plist 中的数据是否作为启动项有效。
| 归档时间: |
|
| 查看次数: |
2898 次 |
| 最近记录: |