ssh expect自动登录的脚本
时间:2014-09-10 18:26 来源:linux.it.net.cn 作者:it
实现:ssh远程登录,每次都要指定一堆用户名和密码,现要求实现自动登录。
登录流程:本地A 先登录到 B 再由B 登录到最终的C
如下:
复制代码代码如下:
#!/usr/bin/expect -f
set timeout 30
spawn ssh B
expect "password:"
send "passwd@\r"
expect "]*"
send "ssh name@C -p port\r"
expect "password:"
send "passwd\r"
interact
要在系统上运行Expect必须首先安装Tcl
#apt-get install expect
(责任编辑:IT)
实现:ssh远程登录,每次都要指定一堆用户名和密码,现要求实现自动登录。
如下:
复制代码代码如下:
#!/usr/bin/expect -f
set timeout 30 spawn ssh B expect "password:" send "passwd@\r" expect "]*" send "ssh name@C -p port\r" expect "password:" send "passwd\r" interact
要在系统上运行Expect必须首先安装Tcl |