因拉取代碼時,需要用另一個系統用戶來拉取。而
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
