expect 两种用法
2019-10-09 17:16
661 查看
yum install expect -y
#先安装expect
1.测试用法
#!/usr/bin/expect #解释语言,这边运行要以./运行,bash运行会报错 spawn ssh root@192.168.0.14 #启动新的进程 expect "*password:" #进程接收字符串,匹配 send "yxy7714707@\r" #前面匹配到了就输入 “ ” 里的内容 expect "*#" send "ifconfig>>123.txt\r" send "exit\r" interact
2.在sh脚本里调用
#!/bin/bash ip=$1 #传递参数 user=$2 password=$3 expect <<EOF set timeout 10 spawn ssh $user@$ip expect { "yes/no" { send "yes\n";exp_continue } "password" { send "$password\n" } } #一个交互用一个expect{} 括起来,这个交互就是登陆的 expect "]#" { send "date>>123.txt\n" } expect "]#" { send "exit\n" } #退出 expect eof EOF
相关文章推荐
- SVN的两种用法
- qt中两种定时器的用法
- jQuery中after的两种用法实例
- expect基本用法
- form表单的两种提交方式,submit和button的用法
- 关于预编译的两种用法
- l线程中 CreateEvent 和 SetEvent及WaitForSingleObject的两种用法
- Eclipse中SVN的安装步骤(两种)和用法
- expect用法--Manpage of EXPECT 的翻译
- java 中 return 的两种常见的用法
- JSP中的include的两种用法
- linux expect 用法小记
- java中synchronize关键字的理解 在多线程环境下的应用: synchronized 关键字,它包括两种用法:synchronized 方法和 synchronized 块。 1. syn
- 水仙花 - %的两种用法
- 两种排序方法(字典序,strcmp的用法)----网易2017内推笔试编程题合集(二)
- spring 事务的两种用法
- expect用法
- expect基本用法
- Sql server 事务的两种用法
- JSP中的include的两种用法