ssh自动登陆

 

 

经过跳板机的登陆一般很麻烦,可以使用 vbs自动登陆脚本。

 

windows下的xshell的vbs登陆脚本

Sub Main
xsh.Screen.Synchronous = true

' xsh.Screen.WaitForString "resource"
xsh.screen.send "2" 
xsh.screen.send Chr(13)
xsh.Screen.WaitForString "account"
xsh.screen.send "root" 
xsh.screen.send Chr(13)
xsh.Session.Sleep 1000
xsh.Screen.WaitForString "password:"
xsh.screen.send "Root@123456" 
xsh.screen.send Chr(13)
xsh.Session.Sleep 1000
xsh.Screen.WaitForString "~$"
xsh.screen.send "ssh admin@120.16.150.141" 
xsh.screen.send VbCr 
xsh.Session.Sleep 5000
xsh.Screen.WaitForString "password:"
xsh.screen.send "Admin@123456" 
xsh.screen.send VbCr
' VbCr is equal to Chr(13)
xsh.Screen.Synchronous = false
End Sub

 

xshell下脚本很多是否无效,特别是 WaitForString  和  WaitForStrings 函数

 

windows下securityCRT的登陆脚本

Sub Main
crt.Screen.WaitForString "select the resource" ,30
crt.screen.send "2" 
crt.screen.send Chr(13)
crt.Screen.WaitForString "account" ,10
crt.screen.send "root" 
crt.screen.send Chr(13)
crt.Screen.WaitForString "password" ,10
crt.screen.send "Root@123456" 
crt.screen.send Chr(13)
crt.Screen.WaitForString "~$" ,10
crt.screen.send "ssh admin@120.16.150.141" 
crt.screen.send Chr(13)
crt.Screen.WaitForString "assword:" ,10
crt.screen.send "Admin@123456" 
crt.screen.send Chr(13)
End Sub

 

 

参考资料:

1、xShell终端调用VBS脚本 使用方法说明

2、 xshell官方手册 http://www.netsarang.com/docs/Xshell5_manual.pdf

3、 shell实现SSH自动登陆

4、 【ssh】通过跳板机自动登录目标服务器 

 

posted @ 2017-05-24 12:35  xunux  阅读(788)  评论(0编辑  收藏  举报