# $language = "VBScript"
# $interface = "1.0"
' $Id$
Option Explicit
Rem 常量,用于检查每条MML命令执行结果
Const CliPrompt = "$>" ' telnet命令提示符
Const CliSuccess = "SUCCESS" ' 命令执行成功
Const CliError = "error" ' 命令执行失败
Rem hostIp为要登陆的 IP
Rem hostPort为登陆的 telnet端口,现在是23
Rem userName为登陆用户
Rem passWord为登录密码
Rem cmdFile为需要发送的命令文件路径和名称,每行一条命令
Rem tmpFile为执行日志文件路径和名称
Const hostIp = "129.0.31.5"
Const hostPort = "23"
Const userName = "tsw"
Const passWord = "tsw"
Const cmdFile = "f:\test\SendAlarm.txt"
Const tmpFile = "f:\test\SendAlarm.log"
Sub Main
Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim fs0, f0, fs1, f1
Dim ln, cmd
Rem When error occured, continue to execute
On Error Resume Next
Do While(1)
crt.Session.Connect("/telnet " & hostIp & " " & hostPort)
Rem crt.Screen.Synchronous = True
crt.Sleep 1000
crt.Screen.Send userName & Chr(13)
crt.Sleep 1000
crt.Screen.Send passWord & Chr(13)
crt.Sleep 1000
Rem ROMB单板需要重新发送一次回车
crt.Screen.Send Chr(13)
Rem 打开MML脚本文件,临时目录下创建结果文件
Set fs0 = CreateObject("Scripting.FileSystemObject" )
Set f0 = fs0.OpenTextFile(cmdFile, ForReading)
Do While f0.AtEndOfStream <> true
Rem Read line
ln = f0.ReadLine
Rem Trim blankspace
cmd = Trim(ln)
Rem For debug
Rem MsgBox("Line: " & cmd)
If Len(cmd) <> 0 Then
Rem Log
Set fs1 = CreateObject("Scripting.FileSystemObject")
Set f1 = fs1.OpenTextFile(tmpFile, ForAppending, True)
f1.WriteLine(Date & " " & Time & " Sending: " & cmd)
f1.Close
Rem Exec command
cmd = cmd & Chr(13)
crt.Screen.Send cmd
Rem check return strings
Rem crt.Screen.WaitForStrings CliSuccess, CliError
Rem 每发送一条告警的等待时间,单位毫秒
crt.Sleep 100
End If
Loop
f0.Close
Rem crt.Screen.Synchronous = False
crt.Session.Disconnect
Rem 15分钟执行1次该命令脚本
crt.Sleep 900000
Loop
End Sub
转载于:https://blog.51cto.com/tswwz/349460