【问题标题】:Git fetch failing in cron. Runs fine manuallyGit fetch 在 cron 中失败。手动运行良好
【发布时间】:2014-11-24 07:58:01
【问题描述】:

整个脚本运行良好。我还要注意,如果我将 cron 作业复制并粘贴到 shell 中并手动运行它,它不会出现任何问题。

Base = '/home/user/git/'
GIT_out = Base + ("git_file.txt")
FILE_NAME =  Base + 'rules/file.xml'
CD_file =  open(Base + "rules/reports/CD.txt", 'r')


os.chdir(Base + 'rules')
gitFetchPull = "git fetch --all   ;sleep 3 ; git pull --all" 
git1 = subprocess.Popen(gitFetchPull, shell=True, stdout=subprocess.PIPE)
gitOut = git1.stdout.read()
print(gitOut) 

当我从 cron 读取输出时,它似乎无法进行身份验证

Received disconnect from 172.17.3.18: 2: Too many authentication failures for tyoffe4
fatal: The remote end hung up unexpectedly
error: Could not fetch origin

定时任务

 * * * /usr/bin/python /home/tyoffe4/git/rules/reports/cd_release.py  >/home/tyoffe4/git/rules/reports/cd_release.out 2>&1

【问题讨论】:

  • 什么是 git remotes 配置?你用什么交通工具?

标签: python git unix cron


【解决方案1】:

这可能是 cron 环境的问题,因为您的 ssh 代理没有设置环境变量。因此,当 git 建立 ssh 连接时,它无法进行身份验证,因为它无法联系您的 ssh 代理并获取密钥。

这个答案可能有你要找的东西: ssh-agent and crontab -- is there a good way to get these to meet?

如果由于某种原因它与 ssh-agent 无关,请尝试在脚本顶部使用 print os.environ 转储所有环境变量的值。

比较 cron 的输出并在 bash shell 中运行 env。可能存在一些差异,其中之一是您的错误的来源。

如果您在 shell 中设置与 cron 中相同的环境变量,该行为应该会重现。

【讨论】:

    猜你喜欢
    • 2016-12-18
    • 2021-11-24
    • 2019-12-07
    • 1970-01-01
    • 2014-12-16
    • 2011-07-27
    • 1970-01-01
    • 1970-01-01
    • 2022-09-30
    相关资源
    最近更新 更多