微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

linux – 如何使脚本执行git pull?

在dev / staging / production服务器上执行git pull是一种常见做法.我经常这样做;我在运行linux的生产服务器上每天执行git pull几乎100次.

我想,是时候制作一个脚本来改进它.

pull.sh将执行这3个命令

> git pull
>输入我的密码(提示时)
>服务Nginx重新加载

我试过在这里创建我的pull.sh

#!/bin/bash

function pull {
  git pull
  password
  service Nginx reload
}


pull ;

结果

运行我的脚本后,我仍然提示输入密码.

enter image description here

任何提示/帮助/建议将不胜感激!

解决方法:

您可以使用expect脚本与git身份验证进行交互:

#!/usr/bin/expect -f
spawn git pull
expect "ass"
send "your_password\r"
interact

它等待“屁股”文本(匹配“密码”,“密码”,“密码短语”),然后它发送您的密码.

可以从另一个重启服务器的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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐