- 论坛徽章:
- 0
|
本帖最后由 飘动de心 于 2016-07-11 10:35 编辑
使用expect实现scp交互,如果密码错误应该要怎么处理?
正常scp,如果密码错误会提示“Permission denied, please try again.”,然后还是要继续输入密码,如下- root@localhost's password:
- Permission denied, please try again.
- root@lcoalhost's password:
复制代码 请问我还可以捕捉*Permission denied, please try again*么,他是上一行的提示,这样正确么
我尝试添加了\"Permission denied, please try again.\" exit,虽然密码错误脚本会退出,但是还是停留在远程机器的命令行上,有什么可以直接取消远程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
复制代码 附实现脚本- ...
- 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
- ...
复制代码 |
|