expect(spawn) 自动化git提交和scp拷贝---centos(linux)

原创
2018/07/18 16:57
阅读数 4.8K

在进行SCP文件拷贝中,往往需要进行用户密码的输入,即用户交互。若采用自动化脚本的方式进行,则可用以下方式

#!/usr/bin/expect

# 设置参数

set src [lindex $argv 0]
set dest [lindex $argv 1]
set password [lindex $argv 2]
set appId [lindex $argv 3]

# 进行拷贝,采用秘钥验证(需要输入秘钥的密码 scp的i参数可指定)方式进行

set timeout 2000
spawn scp -i /home/hadoop/.ssh/id_rsa_soa -r $src $dest
expect {
"(yes/no)" {send "yes\r\n";exp_continue} "*passphrase*:" {send "秘钥的密码\r\n";exp_continue}
"app*:" {send "$password\r\n"}
}
expect eof

在进行git的自动化提交代码可用

#!/usr/bin/expect

cd dir
exec git add .
exec git commit -m "update by yourName"
spawn git push
expect {
"Password*" {send "password\r\n"}
}
expect eof

展开阅读全文
加载中
点击引领话题📣 发布并加入讨论🔥
打赏
0 评论
6 收藏
1
分享
返回顶部
顶部