在进行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