scp linux 自动化,expect(spawn) 自动化git提交和scp拷贝---centos(linux)
在進行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
總結
以上是生活随笔為你收集整理的scp linux 自动化,expect(spawn) 自动化git提交和scp拷贝---centos(linux)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android设备报警推送,Fireba
- 下一篇: linux 修改网卡报错xe,cento