繁体   English   中英

git add,通过expect脚本提交

[英]git add, commit via expect script

在我的工作中为了使用git,github我们需要登录,通过使用函数git_login <user_name>这是一个名为git.sh的脚本的内置函数,然后它要求输入用户密码。

我正在尝试自动执行此过程,期望脚本向我显示我已登录,但在尝试推送或提交时,它要求输入未知用户的密码,它应该是简单的吗?!

#!/usr/bin/expect -f

set timeout 15
set tagName [[lindex $argv 0]
if { [llength $tagName] == 0 } {
    puts "no tag name provided...\n"
    exit 1
}
spawn /bin/bash -c "source git.sh && git_login my_user"
expect "assword: "
send -- "my_password"
expect "is now logged in"
exec git add .
exec git commit "$tagName"
exit

或者代替最后3行

git push origin "$tagName"
exit

我使用-d而不是-f执行脚本(用于调试)

在此输入图像描述

expect脚本显示我已登录

它显然不是:它寻找“ is now logged in ”的glob模式is now logged in但找不到它。

expect自动化工具通常具有如下序列:

expect "password:"
# Send the password, and then wait for a shell prompt.
send "$my_password\r"

(不要expect "assword:"

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM