expect命令自动登录ssh】的更多相关文章

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:"…
使用expect实现自动登录的脚本,网上有很多,可是都没有一个明白的说明,初学者一般都是照抄.收藏.可是为什么要这么写却不知其然.本文用一个最短的例子说明脚本的原理. 脚本代码如下: ############################################## #!/usr/bin/expect set timeout 30 spawn ssh -l username 192.168.1.1 expect "password:" send "ispass\r&…
[http://blog.51yip.com/linux/1462.html#] #!/usr/bin/expect -f set ip 192.168.1.201 set password meimiao1905 set timeout 10 spawn ssh root@$ip expect { "*yes/no" { send "yes\r"; exp_continue} "*password:" { send "$passwor…
有时候我们需要批量发送ssh命令给服务器,但是有可能有些服务器是新加入的,还没有配置ssh免密,这个时候就会提示我们输入yes/no 或者password等,expect脚本命令就是用于在提示这些的时候,自动为我们输入相应的文字 expect脚本 先看一段shell脚本,实现了ssh自动连接 #!/usr/bin/expect spawn ssh 192.168.1.241 expect "password" send "123456\r" expect "…
经常在工作中需要切换到不同的服务器去部署,或者查看日志,每次登录都要去找对应的IP和地址,非常麻烦,最终决定使用iterm2+脚本来实现自动登录. 1.iterm2(下载安装不再介绍http://www.iterm2.com/downloads.html) iterm2->Perferences->Profiles 方法一: command:expect 脚本路径 以下为脚本内容: #!/usr/bin/expect -f set user root set host 10.0.0.1 set…
expect expect可以让我们实现自动登录远程机器,并且可以实现自动远程执行命令.当然若是使用不带密码的密钥验证同样可以实现自动登录和自动远程执行命令.但当不能使用密钥验证的时候,我们就没有办法了.所以,这时候只要知道对方机器的账号和密码就可以通过expect脚本实现登录和远程命令. 引言 目前在公司是一人一台虚拟机,大多数工作都要在虚拟机上完成,为此每天要执行很多次[ssh xxx@xxxxxx]指令登录虚拟机:有很多方式解决这个问题,如使用xshell.secureCRT等工具记录常用…
自动登录主机(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&…
#!/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是 #!/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…
前提条件服务器已经安装过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…