因拉取代码时,需要用另一个系统用户来拉取。而
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}
"
expect "*Password*"
send "${pwd}
"
expect eof
FLAGEOF
需要安装expect:yum -y install expect
然后执行即可:sh git-pull.sh