expect实现自动登录】的更多相关文章

使用expect实现自动登录的脚本,网上有很多,可是都没有一个明白的说明,初学者一般都是照抄.收藏.可是为什么要这么写却不知其然.本文用一个最短的例子说明脚本的原理. 脚本代码如下: ############################################## #!/usr/bin/expect set timeout 30 spawn ssh -l username 192.168.1.1 expect "password:" send "ispass\r&…
自动登录主机(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&…
expect expect可以让我们实现自动登录远程机器,并且可以实现自动远程执行命令.当然若是使用不带密码的密钥验证同样可以实现自动登录和自动远程执行命令.但当不能使用密钥验证的时候,我们就没有办法了.所以,这时候只要知道对方机器的账号和密码就可以通过expect脚本实现登录和远程命令. 引言 目前在公司是一人一台虚拟机,大多数工作都要在虚拟机上完成,为此每天要执行很多次[ssh xxx@xxxxxx]指令登录虚拟机:有很多方式解决这个问题,如使用xshell.secureCRT等工具记录常用…
前提条件服务器已经安装过tcl和expect, 若未安装:可以先执行 yum  install tcl  expect  进行安装 第一步.编写以下自动登录脚本login.sh ############################################## #!/usr/bin/expectset timeout 10 spawn ssh username@172.16.2.1expect "password:"send "password\r"int…
#!/usr/bin/expect -f #设置超时时间 set timeout #这里设置了跳板机的密码 set password "你的跳板机密码" #连接跳板机 spawn ssh 用户名@跳板机IP #如果返回的内容包含*yes/no*,发送yes expect "*yes/no*" {send "yes\n"} #如果返回的内容包含"*password*",发送你设置的密码+\r(PS.这里的\r一定要加,是回车操作…
expect是简单的工具原因,依赖于tcl. 直接apt安装就行. 四个关键字: spawn,派生出新进程. expect,期待得到的字符串,可以模式匹配. send,向进程发送字符串. interact,进入交互模式. 下面是连接ssh例子: #! /usr/bin/expect spawn ssh root@192.168.10.31 expect { "*yes/no" { send "yes\r"; expect "*assword:"…
#!/usr/bin/expect -f set ip [lindex $argv ] set port [lindex $argv ] set username [lindex $argv ] set password [lindex $argv ] set timeout spawn ssh $ip -p $port -l $username expect { ##"*yes/no" { send "yes\r"; exp_continue } "*p…
expect是 #!/bin/bashpasswd='123456'/usr/bin/expect <<EOFset time 30spawn ssh root@192.168.76.10expect { "*yes/no" { send "yes\r"; exp_continue} "*password:" {send "$passwd\r"} }expect "*#"send "c…
因为要对客户方的快30个项目进行特别有顺序的重启,所以不得不想办法写个脚本,网上看了不少段子.真是残缺的可以.没有一段是可以正常运行的.我来按顺序记录一下 脚本的本身 使用expect实现自动登录的脚本,网上有很多,可是都没有一个明白的说明,初学者一般都是照抄.收藏.可是为什么要这么写却不知其然.本文用一个最短的例子说明脚本的原理. 脚本代码如下: ############################################## #!/usr/bin/expect set timeo…
使用expect实现自动登录的脚本,网上有很多,可是都没有一个明白的说明,初学者一般都是照抄.收藏.可是为什么要这么写却不知其然.本文用一个最短的例子说明脚本的原理. 脚本代码如下: #!/usr/bin/expect set timeout spawn ssh -l username 192.168.1.1 expect "password:" send "ispass\r" interact 1. [#!/usr/bin/expect] 这一行告诉操作系统脚本里…