expect 示例
2016-05-26 01:08
239 查看
/usr/bin/expect<<EOF set timeout 50 spawn $SCP_LOG_TO_GATHER_SERVER expect { "*yes/no)?" { send "yes\n" "*password:*" {send "GatherServerPassword\n"} } "*password:" { send "$GatherServerPassword\n" } } expect "*password:" { send "$GatherServerPassword\n" } expect "100%" expect eof EOF or #!/usr/bin/expect set timeout 1 spawn su root -c "/opt/1.sh" expect "password: " send "123456\r" interact exit 最新示例 #!/usr/bin/expect -f //这个expect的路径就是用which expect 查看的结果 spawn su - nginx //切换用户 expect "password:" //提示让输入密码 send "testr" //输入nginx的密码 interact //操作完成 #!/usr/bin/expect set timeout 5 set server [lindex $argv 0] set user [lindex $argv 1] set passwd [lindex $argv 2] spawn ssh -l $user $server expect { "(yes/no)" { send "yesr"; exp_continue } "password:" { send "$passwdr" } } expect "*Last login*" interact #!/usr/bin/expect set timeout 10 set host [lindex $argv 0] //第1个参数,其它2,3,4参数类似 set username [lindex $argv 1] set password [lindex $argv 2] set src_file [lindex $argv 3] set dest_file [lindex $argv 4] spawn scp $src_file $username@$host:$dest_file expect { "(yes/no)?" { send "yesn" expect "*assword:" { send "$passwordn"} } "*assword:" { send "$passwordn" } } expect "100%" expect eof
相关文章推荐
- Linux中使用expect脚本实现远程机器自动登录
- shell中嵌套执行expect命令实例
- expect实现批量修改linux密码脚本分享
- expect实现单台、多台服务器批量scp传输文件
- shell结合expect写的批量scp脚本工具
- expect用法
- expect 打开文件
- expect
- Linux 远程执行命令,expect
- expect应用
- shell:expect实现非root用户切换脚本
- expect ssh ftp
- Expect 自动任务 集中部署
- expect 交互式脚本写法
- expect简单用法
- expect实现自动化模拟输入scp/ssh
- linux expect 用法
- CRemoteExec远程执行类
- linux用scp远程传输文件(自动化)
- linux 快捷登录三 expect脚本