在進行SCP文件拷貝中,每每須要進行用戶密碼的輸入,即用戶交互。若採用自動化腳本的方式進行,則可用如下方式git
#!/usr/bin/expectapp
# 設置參數ssh
set src [lindex $argv 0]
set dest [lindex $argv 1]
set password [lindex $argv 2]
set appId [lindex $argv 3]oop
# 進行拷貝,採用祕鑰驗證(須要輸入祕鑰的密碼 scp的i參數可指定)方式進行spa
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 eofhadoop
在進行git的自動化提交代碼可用:it
#!/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 eofdate