SecureCRT在windows本机执⾏VBS脚本,批量登录linux主机,跳转⽤户,并。
。。
#$language = “VBScript”
$interface = “1.0”
'本脚本⽰范:从⼀个⽂件⾥⾯⾃动读取设备IP地址,密码等,⾃动连接配置⽂件中设备,再执⾏命令
'设计思路,从list列表中获取IP列表与密码以及命令等参数
Sub Main
'打开保存设备管理地址、名称以及密码的⽂件
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fso,file1,line,str1,params
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set file1 = fso.OpenTextFile(“E:\VBS脚本\”,Forreading, False)
crt.Screen.Synchronous = True
'SSH到主应设备上
'crt.Session.Connect ("/SSH2 /PASSWORD “& params(4) & " " & params(2) & “@” & params(0)) crt.Session.Connect (”/SSH2 /PASSWORD jxBdpasw4s+ slview@5x.")
DO While file1.AtEndOfStream <> True
'读出每⾏
line = file1.ReadLine
'分离每⾏的参数 IP地址 密码 En密码
params = Split (line)
'crt.session.LogFileName = “E:\VBS脚本” & params(1) & " " & params(0) & “.txt”
'crt.session.Log(true)
'SSH跳转到⽬标设备linux循环执行命令脚本
str1 = “ssh slview@” & params(0)
crt.Screen.Send str1 & vbcr
crt.Screen.Send “su - root” & vbcr
crt.Screen.WaitForString “passwd:”,1
crt.Screen.Send params(3) & vbcr
crt.Sleep 3000
crt.Screen.Send “ifconfig|grep addr” & vbcr
'crt.Screen.waitForString “#”
crt.Sleep 3000
'此处修改执⾏的命令
crt.Screen.Send “/etc/init.d/nfslock stop;/etc/init.d/nfslock status” & vbcr
crt.Screen.Send “exit” & vbcr
crt.Sleep 3000
crt.Screen.Send “exit” & vbcr
crt.Sleep 3000
Do Until crt.Screen.WaitForString (“11111111111111”,3) = False
loop
'执⾏完成后退出
'crt.Session.Disconnect
loop
crt.Screen.Synchronous = False
End Sub
<样式
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论