expect使用】的更多相关文章

1. [#!/usr/bin/expect]  这一行告诉操作系统脚本里的代码使用那一个shell来执行.这里的expect其实和linux下的bash.windows下的cmd是一类东西.  注意:这一行需要在脚本的第一行.  2. [set timeout 30]  基本上认识英文的都知道这是设置超时时间的,现在你只要记住他的计时单位是:秒.timeout -1 为永不超时 3. [spawn ssh -l username 192.168.1.1]  spawn是进入expect环境后才可…
参考: http://www.cnblogs.com/lzrabbit/p/4298794.html expect是linux系统中可以和子进程进行交互的一个命令,使用它可以做一些自动化工作.python中也有一个模块pexpect,提供了类似的功能. 例如:使用ssh登陆需要输入密码,可以使用expect代替手工输入. 例如:使用passwd修改账户密码,也可以使用expect代替. expect用多种执行方式,交互式,执行文件,执行命令. 1.交互式 在命令行输入expect进入交互式 常用…
自动登录主机(ssh) 建脚本item2login.sh,包含如下内容 #!/usr/bin/expect set timeout 30 spawn ssh -p [lindex $argv 0] [lindex $argv 1]@[lindex $argv 2] expect { "(yes/no)?" {send "yes\n";exp_continue} "password:" {send "[lindex $argv 3]\n&…
  Mac 下载:brew install homebrew/dupes/expect expect : ->  自动化脚本工具:  用于处理交互命令; #注意 调用时并不是使用的 /bin/bash 而是 expect#!/usr/local/bin/expect Expect中最关键的四个命令是send,expect,spawn,interact. send:用于向进程发送字符串  expect:从进程接收字符串  {捕捉返回信息中的字符串} spawn:启动新的进程   {启动新的进程}…
#!/usr/bin/expect -fset ipaddr "192.168.5.4"set passwd "123qwe"set timeout 30 spawn ssh root@$ipaddrexpect {"yes/no" { send "yes\r"; exp_continue }"password: " { send "$passwd\r" }}expect "*…
[root@localhost scripts]# cat exptest.sh #!/usr/bin/expect spawn ssh root@127.0.0.1 expect "password: " send "oracle\r" send "ls\r" #send "ls >/tmp/l3.log\r" send "echo status:$?\r" expect -re ,string)…
#!/usr/bin/expect set hostname [lindex $argv 0] set username [lindex $argv 1] set passwd [lindex $argv 2] set dbname [lindex $argv 3] set timeout 10 #spawn /usr/bin/ssh $username@$hostname #expect { # "yes/no" { send "yes";exp_continue…
测试框架Mocha与断言expect在浏览器和Node环境都可以使用除了Mocha以外,类似的测试框架还有Jasmine.Karma.Tape等,也很值得学习. 整个项目源代码: 为什么学习测试代码?1. react的开发不适合网页端的调试和测试2. 把关所写代码质量,防止bug和漏洞 要测试的文件add.js测试文件命名为:add.test.js或者add.spec.js 测试脚本可以独立运行.测试脚本里包含一个或多个describe块,每个describe块应该包括一个或多个it块 add.…
简单模式: #!/usr/bin/expect -f spawn ssh root@192.168.0.1 expect "*assword*" send "root\r" expect "#" send "ifconfig \r" expect eof 讲解: send:用于向进程发送字符串 expect:从进程接收字符串 比如:expect "*assword*" spawn:启动新的进程 intera…
一.命令 except 实例详解 1. 介绍 expect 使用场景 expect可以让我们实现自动登录远程机器,并且可以实现自动远程执行命令.当然若是使用不带密码的密钥验证同样可以实现自动登录和自动远程执行命令.但当不能使用密钥验证的时候,我们就没有办法了.所以,这时候只要知道对方机器的账号和密码就可以通过expect脚本实现登录和远程命令. 使用之前先安装 expect 软件 yum install -y expect 2. 自动远程登录,登陆后不退出 #! /usr/bin/expect…