我创建了一个shell脚本文件,用于使用crontab每小时自动推送git仓库,如下所示,
backup.sh
cd /home/user/share/my_project && git commit -a -m "hourli crontab backup 'date'"
cd /home/user/share/my_project && git push origin branch1
send mypassword\r
wait
此代码的问题是,git使用ssh,并且每次我们使用bash ./backup.sh
运行此代码时,都要求在终端输入密码。不接受外壳程序脚本中指定的密码。
答案 0 :(得分:0)
我同意这不是最佳做法的评论。
不管怎样,无论如何都要进行黑客入侵,您应该研究git-credential-store。文档中的示例;
$ git config credential.helper store
$ git push http://example.com/repo.git
Username: <type your username>
Password: <type your password>
[several days later]
$ git push http://example.com/repo.git
[your credentials are used automatically]
凭据将存储在本地,未在~/.git-credentials
中加密。如果这是一个可以接受的折衷方案,那么它将为您服务。只需确保您了解cron作业正在其下运行的用户上下文即可。