Linux 如何制作脚本来执行git pull?
通常的做法是在dev/staging/生产服务器上执行Linux 如何制作脚本来执行git pull?,linux,git,bash,shell,Linux,Git,Bash,Shell,通常的做法是在dev/staging/生产服务器上执行git pull。我自己经常这样做;我每天在运行linux的生产服务器上执行git pull几乎100次 我想,是时候制作一个脚本来改进它了 pull.sh将执行这3个命令 吉特拉力 输入我的密码(提示时) 服务nginx重新加载 我已尝试在此处创建我的pull.sh #!/bin/bash function pull { git pull password service nginx reload } pull ;
git pull
。我自己经常这样做;我每天在运行linux的生产服务器上执行git pull几乎100次
我想,是时候制作一个脚本来改进它了
pull.sh将执行这3个命令
- 吉特拉力
- 输入我的密码(提示时)
- 服务nginx重新加载
我已尝试在此处创建我的pull.sh
#!/bin/bash
function pull {
git pull
password
service nginx reload
}
pull ;
结果 在运行我的脚本之后,我仍然得到输入密码的提示
任何提示/帮助/建议都将不胜感激 您可以使用
expect
脚本与git身份验证进行交互:
#!/usr/bin/expect -f
spawn git pull
expect "ass"
send "your_password\r"
interact
它等待“ass”文本(与“Password”、“Password”、“passphrase”匹配),然后发送您的密码
可以从另一个将重新启动服务器的bash脚本调用该脚本:
# Call script directly since the shell knows that it should run it with
# expect tool because of the first script line "#!/usr/bin/expect -f"
./git-pull-helper-script.sh
# Without the first line "#!/usr/bin/expect -f" the file with commands
# may be sent explicitly to 'expect':
expect file-with-commands
# Restart server
service nginx reload
处理密码短语的方法是使用ssh代理:这样,您只需要输入一次密码短语 我在我的开发者用户的
~/.bash\u配置文件中有这个
# launch an ssh agent at login, so git commands don't need to prompt for password
# ref: http://stackoverflow.com/a/18915067/7552
SSH_ENV=$HOME/.ssh/env
if [[ -f ~/.ssh/id_rsa ]]; then
function start_agent {
# Initialising new SSH agent...
ssh-agent | sed 's/^echo/#&/' > "${SSH_ENV}"
chmod 600 "${SSH_ENV}"
source "${SSH_ENV}" > /dev/null
ssh-add
}
# Source SSH settings, if applicable
if [ -f "${SSH_ENV}" ]; then
source "${SSH_ENV}" > /dev/null
agent_pid=$(pgrep ssh-agent)
(( ${agent_pid:-0} == $SSH_AGENT_PID )) || start_agent
unset agent_pid
else
start_agent
fi
fi
哪个应用程序要求您输入您的密码?您累了什么。在此过程中,您访问了哪些网站?这不完全是你要找的一个研究网站。每次我执行git pull
时,它通常会提示我输入密码。最有可能是通过ssh
远程访问。为什么eval
到处都是?这是一个合法的问题,我不知道为什么有两个人投票支持关闭。我非常感谢您的关心和帮助。:)@我希望您需要将提示字符串调整为“回车…”即可。你介意解释一下什么是bin/expect-f
?#/usr/local/bin/expect-f
它告诉您的系统通过expect
application:expect读取cmdfile以获取要执行的命令列表来处理脚本。Expect也可以在支持#的系统上隐式调用!标记脚本可执行文件,并在脚本中创建第一行。此脚本不由bash处理。它由另一个应用程序解释expect
。expect脚本完成后,您可以运行其他shell命令,如service nginx reload