#$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脚本\list.txt”,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.5x.1xx.xxx”)
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跳转到目标设备
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
list.txt样式