【问题标题】:Bash Script Runs From Command Line But Not With LaunchdBash 脚本从命令行运行,但不能使用 Launchd
【发布时间】:2019-11-15 23:14:31
【问题描述】:

我在 2010 年运行 Mavericks 的 MBA 上运行 autossh。该脚本运行良好,并且在命令行中按预期工作,但在由 launchd 运行时却不行。

我尝试在启动的 plist 中包含 PATH,但这没有帮助。

这是脚本:

#!/bin/bash

/opt/local/bin/autossh -M 0 -f -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -o "ExitOnForwardFailure yes" -R 19990:localhost:22 mnewman@super.myddns.rocks -p 10000

我尝试过使用和不使用“ExitOnForwardFailure yes”

这是列表:

<?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>Disabled</key>
    <false/>
    <key>EnvironmentVariables</key>
    <dict>
        <key>PATH</key>
        <string>/opt/local/bin:/opt/local/sbin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin
</string>
    </dict>
    <key>KeepAlive</key>
    <true/>
    <key>Label</key>
    <string>com.mgnewman.autossh</string>
    <key>ProgramArguments</key>
    <array>
        <string>/Users/mnewman/bin/autossh.sh</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
</dict>
</plist>

我尝试过使用和不使用 PATH 键。

我希望能够远程登录到这台机器。我也尝试过仅使用 ssh 并且它可以从命令行和 launchd 正常运行:

#!/bin/bash

ssh -NTC -o ServerAliveInterval=60 -o ExitOnForwardFailure=yes -R 19999:172.16.0.56:22 mnewman@super.myddns.rocks -p 10000

当然,由于 ssh 有效,我实际上并不需要 autossh,但我想知道为什么它不适合我。

【问题讨论】:

  • 我已经设置了 StandardErrorPath 和 StandardOutPath,但是那里什么都没有。我也将 debug 设置为 true,但 system.log 中唯一的内容是:
  • 我已经设置了 StandardErrorPath 和 StandardOutPath,但是那里什么都没有。我也将 debug 设置为 true,但 system.log 中唯一的内容是:Jul 6 06:27:27 Axe com.apple.launchd.peruser.504[173] (com.mgnewman.autossh): Throttling respawn: Will start in 10 seconds 我不知道还能做什么。

标签: bash ssh osx-mavericks launchd autossh


【解决方案1】:

现在工作。原来为了让它与launchd一起工作,我不得不向shell脚本添加两个参数:“-f”在后台运行,“-N”不执行任何命令。我不知道为什么会这样。

#!/bin/bash

/opt/local/bin/autossh -f -M 0 -N -o "ServerAliveInterval 30" -o "ServerAliveCountMax 3" -R 19990:localhost:22 mnewman@ksuper.myddns.rocks -p 10000 

【讨论】:

    猜你喜欢
    • 2012-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-01-02
    • 1970-01-01
    • 2015-01-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多