可以直接通过包管理工具下载
yum install expect 或者 apt install expect
第一种
通过while 配合read拉取
#!/usr/bin/expect
passwd="xxx"
username="xxx"while read -r addr
do
expect << L
set timeout -1 ##表示永不超时
spawn git clone -b $addr ##开启一个交互
expect {
"*Username*" { send "$username\r"; exp_continue } ##exp_continue继续匹配不写会结束,相当于需要写两个expect
"*Password*" { send "$passwd\r" }
}
expect eof ##结束一个交互
L
done < ./addr当前目录创建一个addr文件里面放自己的git地址
master https://xxx/xxx.git xxx
master4 https://xxx1/xxx.git xxx
第二种
通过addr列表循环取出git地址
#!/bin/sh
passwd="xxx"
username="xxx"addr=("https://xxx/xxx.git xxx"
"https://xxx1/xxx.git xxx")gitclone() {
expect << L
set timeout -1
spawn git clone $1
expect {
"*Username*" { send "$username\r"; exp_continue }
"*Password*" { send "$passwd\r" }
}
expect eof
L
}##循环取出addr列表的地址,可以写多个
for addr in "${addr[@]}"; do
gitclone $addrdone