如何将 git 通过 netrc.gpg 文件获取到 crontab

How to apply git fetch through netrc.gpg file to crontab

我目前正计划在 redmine 中注册并使用 git 存储库。

因为 redmine 不是通过远程 url 管理的,所以有一个问题,您必须 git 克隆它并定期离开提取。

本来可以通过 git credential store 简单地处理,但我认为存在安全问题,所以我用 netrc.gpg 文件加密了 netrc 文件,然后制作git-credential-netrc 文件通过 git.credential = netrc -v.

获取

这些任务是在看到下面的参考资料后写的。

  1. is-there-a-way-to-cache-github-credentials-for-pushing-commits

特别是我参考了参考号1,我也检查了shell脚本在本地打开后是否正常运行shell脚本如下

#!/bin/bash
cd ${PROJECT_DIR}

for entry in `ls -d */`
    do
        echo "$entry"
        cd ${entry}  && {
                git remote update
                cd ..
            }
    done

但是将这个shell脚本文件转成crontab定时运行时出现了问题

# m h  dom mon dow   command
 */1 * * * * /home/vanilla/redmine/docker-redmine/update-git-repo.sh >> ~/cron.log 2>&1

一开始以为是用户权限问题,结果shell脚本在vanilla用户操作时运行正常,查看了crontab文件用户 crontab -e -u vanilla 并确认它在文件中。

有什么问题?

我在我使用的 git-credential-netrc 中的文件中附加了一个 link,虽然我不知道它是否有帮助。

git-credential-netrc.perl

这是一个非常简单的问题。 我如下更改了 git 全局凭据选项,它已解决。

git config --global credential.helper /usr/local/bin/git-credential-netrc

在运行本地shell脚本中,它作为git config --global credential.helper "netrc -v"命令工作,但在crontab的情况下,必须指定实际命令的位置并注册为凭据由于环境变量或其他问题。

https://gist.github.com/soardex/bd588f633d03d8bd0f84