- 論壇徽章:
- 0
|
本帖最后由 飄動de心 于 2016-07-11 10:35 編輯
使用expect實(shí)現(xiàn)scp交互,如果密碼錯誤應(yīng)該要怎么處理?
正常scp,如果密碼錯誤會提示“Permission denied, please try again.”,然后還是要繼續(xù)輸入密碼,如下- root@localhost's password:
- Permission denied, please try again.
- root@lcoalhost's password:
復(fù)制代碼 請問我還可以捕捉*Permission denied, please try again*么,他是上一行的提示,這樣正確么
我嘗試添加了\"Permission denied, please try again.\" exit,雖然密碼錯誤腳本會退出,但是還是停留在遠(yuǎn)程機(jī)器的命令行上,有什么可以直接取消遠(yuǎn)程scp 打印密碼錯誤- [root@localhost test]# ./remote_scp 192.168.1.10 123456
- expect: spawn id exp6 not open
- while executing
- "expect eof "
- spawn ssh root@192.168.1.10
- root@192.168.1.10's password:
- Permission denied, please try again.
- root@192.168.1.10's password: ^[[A^[[A^H^H^H^H^H^C[root@localhost test]# ^C
復(fù)制代碼 附實(shí)現(xiàn)腳本- ...
- expect -c "
- set timeout 1800;
- spawn scp -r $dir root@$ip_addr:~/
- expect {
- \"(yes/no)?\" {send \"yes\r\";exp_continue}
- \"*password:\" {send \"$passwd\r\"}
- }
- expect eof " >>$log
- ...
復(fù)制代碼 |
|