1.??expect的应用
?1)传输文件
?2)远程执行命令,无需交互,无需输入密码
?3)上线的shell脚本(工具),核心是expect,即分发系统
2. expect的安装
? ?yum install? -y expect
3.??expect语言实例1:自动远程登陆某台服务器
#! /usr/bin/expect set host "192.168.133.132" set passwd "123456" spawn ssh [email?protected]$host expect { "yes/no" { send "yesr"; exp_continue} "password:" { send "$passwdr" } } interact |
4.?expect语言实例2:自动远程登陆某台服务器后,并执行命令
#!/usr/bin/expect set user "root" set passwd "123456" spawn ssh [email?protected] expect { "yes/no" { send "yesr"; exp_continue} "password:" { send "$passwdr" } } expect "]*" send "touch /tmp/12.txtr" expect "]*" send "echo 1212 > /tmp/12.txtr" expect "]*" send "exitr" |
5. expect脚本之传递参数
#!/usr/bin/expect set user [lindex $argv 0] set host [lindex $argv 1] set passwd "123456" set cm [lindex $argv 2] spawn ssh [email?protected]$host expect { "yes/no" { send "yesr"} "password:" { send "$passwdr" } } expect "]*" send "$cmr" expect "]*" send "exitr" |
? ? ???$argv0?? 表示要传递给变量user的参数;$argv1,$argv2同理
6.?expect脚本之同步文件
? ?

7.??expect脚本之构建文件分发系统
? ?

8.?
#!/usr/bin/expect set host [lindex $argv 0] set passwd "123456" set cm [lindex $argv 1] spawn ssh [email?protected]$host expect { "yes/no" { send "yesr"} "password:" { send "$passwdr" } } expect "]*" send "$cmr" expect "]*" send "exitr" |