git http 拉取代码 自动输入用户名和密码

因拉取代码时,需要用另一个系统用户来拉取。而

git config --global credential.helper store

保存在root用户下(应该也可以通过修改权限等方式来解决,这里不讨论这个方案)。

#!/bin/bash

user_name="xxxx@163.com"
pwd="123456"

cd /var/www/html/kangaroo

/usr/bin/expect << FLAGEOF

set timeout 10

spawn sudo -u apache git pull origin
expect "*Username*"
send "${user_name}\r"
expect "*Password*"
send "${pwd}\r"
expect eof

FLAGEOF

需要安装expect:yum -y install expect

然后执行即可:sh git-pull.sh

posted @ 2021-06-21 17:16  流失的痕迹  阅读(603)  评论(0编辑  收藏  举报