尝试使用 launchd .plist 文件运行 shell 脚本时权限被拒绝
我正在尝试创建一个新的 launchagent 文件,该文件将执行 shell 脚本来对 ftp 文件夹执行备份。 .plist 文件的内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" \
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.team.backup</string>
<key>ProgramArguments</key>
<array>
<string>/Users/jackm/Documents/Uni/backup.sh</string>
</array>
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Hour</key>
<integer>15</integer>
<key>Minute</key>
<integer>30</integer>
</dict>
</array>
<key>StandardErrorPath</key>
<string>/Users/jackm/Documents/Uni/backup_err.log</string>
</dict>
</plist>
backup.sh 文件如下:
#!/bin/bash
scp -r [email protected]:/the/ftp/folder/ "/Users/jackm/morefolders/Backups/D2 Backup/$(date '+%d-%b-%H:%M')"
当我通过终端执行时,backup.sh 文件运行得非常好,要求我输入密码,然后下载文件夹。 不过,当使用 launchd 时,我什至没有收到输入密码的提示,我只是在错误日志文件中看到以下内容:
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
launchctl list 给出 plist 的状态为 1。 ~/etc/ssh_config 密码确认为 1 .plist 文件位于 launchagents 文件夹
中
I'm trying to create a new launchagent file that will execute a shell script to perform a backup on an ftp folder.
the content of the .plist file is as follows:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" \
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.team.backup</string>
<key>ProgramArguments</key>
<array>
<string>/Users/jackm/Documents/Uni/backup.sh</string>
</array>
<key>StartCalendarInterval</key>
<array>
<dict>
<key>Hour</key>
<integer>15</integer>
<key>Minute</key>
<integer>30</integer>
</dict>
</array>
<key>StandardErrorPath</key>
<string>/Users/jackm/Documents/Uni/backup_err.log</string>
</dict>
</plist>
the backup.sh file is as follows:
#!/bin/bash
scp -r [email protected]:/the/ftp/folder/ "/Users/jackm/morefolders/Backups/D2 Backup/$(date '+%d-%b-%H:%M')"
The backup.sh file runs absolutely fine when I execute via terminal, asks me for a password then downloads the folder.
When using the launchd though, I do not even get prompted for a password, I just get the following in the error log file:
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-keyex,gssapi-with-mic,password).
launchctl list gives the plist as having status 1.
~/etc/ssh_config PasswordConfirmation is 1
the .plist file is in the launchagents folder
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当通过 launchd 运行时,您的脚本没有附加交互式 tty,因此无法提示输入密码。您应该改为设置公钥身份验证。
When run via launchd, your script doesn't have an interactive tty attached and thus cannot prompt for a password. You should set up public key authentication instead.