关于secureCRT的问题,高手请进,谢谢!

2024-12-22 21:34:49
推荐回答(2个)
回答1:

# $language = "VBScript"
# $interface = "1.0"

Sub main

Dim fso, fHost,fCMDbsn,fCMDscs, strLineHost,strLineCommand,strLogfile,strArray

Const ForReading = 1
Const Hostip=0
Const NodeType=1
Const ScriptPath=""

Set fso = CreateObject("Scripting.FileSystemObject")
ScriptPath=fso.GetParentFolderName(WScript.ScriptFullName)

LogPath=ScriptPath & "\log\"

Set fso = CreateObject("Scripting.FileSystemObject")
Set fHost = fso.OpenTextFile(ScriptPath& "tz.txt", ForReading, 0)
'
Do While fHost.AtEndOfStream <> True
crt.Screen.Synchronous =0
strLineHost = Trim(fHost.Readline )
strArray=split(strLineHost,vbtab,-1)
strLogfile=LogPath & strArray(hostip)
crt.Session.LogFileName = strLogfile

crt.Screen.WaitForString "$"

crt.Session.Log True
crt.Screen.Send "telnet" & " " & strArray(Hostip) & vbcr

crt.screen.waitforstring "ogin:"
crt.screen.send "admin" & vbcr

crt.screen.waitforstring "assword:"
crt.screen.send "admin" & vbcr

If strArray(NodeType)="SW" Then
Set fCMDbsn=fso.OpenTextFile(ScriptPath& "dao_cmd.txt", ForReading, 0)
Do While fCMDbsn.AtEndOfStream <> True
strLineCommand=Trim(fCMDbsn.Readline)
Do While strLineCommand="wait"
crt.sleep 5000
strLineCommand=Trim(fCMDbsn.Readline)
Loop
crt.Screen.WaitforString "#"
crt.Screen.Send strLineCommand & vbcr
call checkend()
Loop
Set fCMDbsn=nothing
Else
Set fCMDscs=fso.OpenTextFile(ScriptPath& "cmdscs.txt", ForReading, 0)
Do While fCMDscs.AtEndOfStream <> True
strLineCommand=Trim(fCMDscs.Readline)
crt.Screen.WaitforString "#"
crt.Screen.Send strLineCommand & vbcr
Loop
Set fCMDscs=nothing
End If
'Logout node
crt.screen.waitforstring "#"
crt.screen.send "quit" & vbcr
crt.screen.send "y" & vbcr
'Stop log file action
crt.screen.waitforstring "$"
crt.screen.send vbcr
crt.Session.Log False
crt.Screen.Synchronous = False
Loop

Set fso=nothing

End Sub

Sub CheckEnd()
Do Until crt.Screen.WaitForString ("#", 1)=True
crt.Screen.Send " "
Loop
crt.Screen.Send vbcr

Exit Sub

End Sub

这是我以前做的一个脚本。供你参考一下。

回答2:

敲入命令script,在这之后的所有命令就被收集在一个文件里。稍加修改,可作为脚本。

想要把比如ls 命令输出的内容保存在一个文件里,比如 output.txt
就用
ls > output.txt

我认为,脚本是由命令构成的。路由器的状态信息,可以保存为文本文件。要把它保存为脚本?希望我没有误解你的意思。