expect是一种自动交互语言,能实现在shell脚本中为scp和ssh等自动输入密码自动登录。
下面给出scp和ssh的使用示例:
1、scp
- expect -c "
- spawn scp [email protected]:/root/1.log /root
- expect {
- "*assword" {set timeout 300; send "passwordr";}
- "yes/no" {send "yesr"; exp_continue;}
- }
- expect eof"
2、ssh
- #!/bin/bash
- expect -c "
- spawn ssh [email protected] "ls;"
- expect {
- "*assword" {set timeout 300; send "passwordr";}
- "yes/no" {send "yesr"; exp_continue;}
- }
- expect eof
- "