zl程序教程

您现在的位置是:首页 >  系统

当前栏目

Linux:expect实现自动拉取git代码

LinuxGit自动代码 实现 拉取 expect
2023-09-27 14:24:16 时间

安装

$ yum install expect
$ where expect

使用

$ expect
expect1.3> expect "hi" {send "hello\n"}
hi
hello

自动拉取git代码

主要解决自动输入账号密码的问题,如果是ssh拉取就不需要使用了
gitpull.exp

#!/usr/bin/expect
set user [lindex $argv 0]
set password [lindex $argv 1]
set timeout 10

spawn git pull
expect "Username*"
send "$user\n"
expect "Password*"
send "$password\n"
expect eof

使用方法

expect gitpull.exp <username> <password>

<username> 替换成自己的账号
<password> 替换成自己的密码

参考:
Linux-expect命令详解
Expect工具的安装及使用方法