尝试使用 launchd .plist 文件运行 shell 脚本时权限被拒绝

发布于 2024-12-26 14:22:58 字数 1647 浏览 1 评论 0原文

我正在尝试创建一个新的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心房的律动 2025-01-02 14:22:58

当通过 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文