+ -
当前位置:首页 → 问答吧 → 用Shell自动建立ssh连接

用Shell自动建立ssh连接

时间:2011-07-06

来源:互联网

Linux服务器上,需要检测ssh连接是否连接正常,如果连接正常就不用管,如果不正常(比如连接断开),那么我想重新建立ssh连接。

每次连接时候,输入一下命令会出现用 hostname's password: 然后需要输入密码,请问这时我需要如何写shell,才能让密码自动输入呢?

[sean@testserver2 ~]$ ssh -lproxy-user -L3555:127.0.0.1:3555 219.90.127.7
[email protected]'s password: <---就是这里不知道怎么让密码自动输入,然后登录。

谢谢!

作者: longxiang333   发布时间: 2011-07-06

#!/usr/bin/expect -f  
  
set port port_no  
set user user_name  
set host host_name  
set password my_password  
set timeout -1  
  
spawn ssh -D $port $user@$host  
expect "*assword:*"  
  
send "$password\r"  
expect eof

作者: linlan999   发布时间: 2011-07-06

interact
expect eof

似乎要加上这句

作者: linlan999   发布时间: 2011-07-06