SecureCRT脚本(VBS)运行
在SecureCRT运行脚本,自动收发数据监控记录运行状态。
参考:
示例代码:
#$language = "VBScript"
#$interface = "1.0"
'====本脚本说明:=================================================
'通信测试:
'1、新建日志文件路径修改LOG_FILE_NAME宏定义的地址
'2、使用Telnet登陆PPC后运行脚本,运行一段时间后错误信息将自动存储到1中定义的文本文件,若无则测试通过。
'
const LOG_FILE_NAME="z:\secureCrt-log.txt"
'================================================================
Sub Main
'================================================================
crt.Screen.Synchronous = True
'--------------------------------
Dim erro_c
erro_c = 1
'----------------------------------------------------------------------------------1
'loop
'crt.Screen.Synchronous = False
'crt.Sleep 1000
crt.Screen.Send "d 0xfa050100" & chr(13)
crt.Sleep 100
crt.Screen.Send "d 0xfa050100" & chr(13)
crt.Screen.waitForString "fa050100: 0000 0002 0002 28b0 0000 ffff"
crt.Screen.waitForString "value = 21 = 0x15"
crt.Sleep 100
'----------------------------------------------------------------------------------2
'Do
'INTI
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0049" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "004E" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0054" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0049" & chr(13)
crt.Screen.Send "q" & chr(13)
Read1
RunRecd
'Loop
'-------------------------------------------
Dim var1
'定义循环次数
var1=5
Const Delay1 = 10
Do
'----------------------------------------------------------------------------------3
'53410000
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0053" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0041" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0080" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0000" & chr(13)
crt.Screen.Send "q" & chr(13)
erro_c = Read2(erro_c )
crt.Sleep Delay1
'53410000
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0053" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0041" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0070" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0000" & chr(13)
crt.Screen.Send "q" & chr(13)
erro_c = Read2(erro_c )
crt.Sleep Delay1
'53410000
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0053" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0041" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0060" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0000" & chr(13)
crt.Screen.Send "q" & chr(13)
erro_c = Read2(erro_c )
crt.Sleep Delay1
'53410000
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0053" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0041" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0050" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0000" & chr(13)
crt.Screen.Send "q" & chr(13)
erro_c = Read2(erro_c )
crt.Sleep Delay1
'53410000
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0053" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0041" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0040" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0000" & chr(13)
crt.Screen.Send "q" & chr(13)
erro_c = Read2(erro_c )
crt.Sleep Delay1
'53410000
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0053" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0041" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0030" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Screen.Send "m 0xfa05010a" & chr(13)
crt.Screen.Send "0000" & chr(13)
crt.Screen.Send "q" & chr(13)
crt.Sleep Delay1
erro_c = Read2(erro_c )
crt.Sleep Delay1
'--------------------------------------------
if var1=1 then
exit do
end if
'var1=var1-1
Loop
'crt.Screen.Send "d 0xfa050100" & chr(13)
'crt.Sleep 1000
crt.Screen.Synchronous = False
End Sub
'=====================================
Sub Read1
crt.Sleep 100
crt.Screen.Send "d 0xfa050100" & chr(13)
crt.Screen.waitForString "0049"
crt.Screen.waitForString "value = 21 = 0x15"
crt.Sleep 500
crt.Screen.Send "d 0xfa050100" & chr(13)
crt.Screen.waitForString "004b"
crt.Screen.waitForString "value = 21 = 0x15"
crt.Sleep 500
crt.Screen.Send "d 0xfa050100" & chr(13)
crt.Screen.waitForString "004b"
crt.Screen.waitForString "value = 21 = 0x15"
crt.Sleep 500
End Sub
'=====================================
Function Read2(e_cnt)
Const Delay2 = 100
crt.Sleep 300
crt.Screen.Send "d 0xfa050100" & chr(13)
'crt.Screen.waitForString "0053"
If(crt.Screen.WaitForString ("0053",1)<>False) Then
'Msgbox "time yes"
crt.Screen.waitForString "value = 21 = 0x15"
Else
ErroRecd e_cnt
e_cnt = e_cnt + 1
crt.Screen.Send "d 0xfa050100" & chr(13)
crt.Screen.Send "d 0xfa050100" & chr(13)
Read2 = e_cnt
exit function
'Msgbox "time out"
End If
crt.Sleep Delay2
crt.Screen.Send "d 0xfa050100" & chr(13)
'crt.Screen.waitForString "004b"
'crt.Screen.waitForString "value = 21 = 0x15"
If(crt.Screen.WaitForString ("004b",1)<>False) Then
'Msgbox "time yes"
crt.Screen.waitForString "value = 21 = 0x15"
Else
ErroRecd e_cnt
e_cnt = e_cnt + 1
crt.Screen.Send "d 0xfa050100" & chr(13)
crt.Screen.Send "d 0xfa050100" & chr(13)
Read2 = e_cnt
exit function
'Msgbox "time out"
End If
crt.Sleep Delay2
crt.Screen.Send "d 0xfa050100" & chr(13)
'crt.Screen.waitForString "004b"
'crt.Screen.waitForString "value = 21 = 0x15"
If(crt.Screen.WaitForString ("004b",1)<>False) Then
'Msgbox "time yes"
crt.Screen.waitForString "value = 21 = 0x15"
Else
ErroRecd e_cnt
e_cnt = e_cnt + 1
crt.Screen.Send "d 0xfa050100" & chr(13)
crt.Screen.Send "d 0xfa050100" & chr(13)
Read2 = e_cnt
exit function
'Msgbox "time out"
End If
crt.Sleep Delay2
Read2 = e_cnt
End Function
'=====================================
Sub ErroRecd(e_cnt)
'创建文件对象
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
'设置文件对象 1 只读模式;2 写模式;8 在文件末尾进行写操作
Set file1 = fso.OpenTextFile(LOG_FILE_NAME,8, False)
'file1.WriteLine("Erro"&e_cnt&":"&time)
file1.WriteLine("Erro"&e_cnt&":"&date&" | "&time)
'---------------------
file1.WriteLine("---------st-----------")
dim s
dim c
c=1
do
s = crt.Screen.Get(c,1,c,100)
file1.WriteLine(s)
if c=50 then
exit do
end if
c=c+1
loop
file1.WriteLine("---------end-----------")
file1.WriteLine(" ")
'---------------------------------------
file1.Close '关闭文件
'Msgbox time
End Sub
'=======================================
Sub RunRecd
'创建文件对象
Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")
'设置文件对象 1 只读模式;2 写模式;8 在文件末尾进行写操作
Set file1 = fso.OpenTextFile(LOG_FILE_NAME,8, False)
'file1.WriteLine("Erro"&e_cnt&":"&time)
file1.WriteLine("|=======================================")
file1.WriteLine("The vbs started@"&":"&date&" | "&time)
'---------------------
file1.WriteLine(" ")
'---------------------------------------
file1.Close '关闭文件
'Msgbox time
End Sub
操作步骤: