crt脚本退出命令_SecureCRT下的批命令脚本 | 学步园

下面的脚本是在SecureCRT下运行的,采用vbs语言编写。把所有的配置命令放在一个文本文件中,然后使用测试脚本来执行这些命令,简化测试过程中的配置过程。

这个脚本在SecureCRT Version 4.0 (build 358)上调试通过。

执行前,根据自己的需要,修改一下CliPrompt、CliError、ShowError等常量。

CliPrompt是CLI的命令提示符

CliError是配置出错时显示的出错提示信息,用来判别命令的执行结果

ShowError表示在出错时,是不是显示一个提示框

在执行时,会提示输入一个命令列表文件名,然后执行这个文件中的所有命令。缺省的列表文件名是cmds.txt。

命令列表文件的格式很简单,每条命令单独放在一行里

如果一行的第一个字符是"#",表示这行是注释行,在执行时被跳过

如果一行中没有任何字符,或者只有空格,则认为是空白行,在执行时被跳过

希望对大家有帮助。

# $language = "VBScript"

# $interface = "1.0"

' $Id$

Option Explicit

' constant

Const CliPrompt = "$"      ' CLI prompt

Const CliError = "Error"        ' the prompt when command exec error

Const ShowError = 1             ' If you dont want to see error msg, change to 0

Sub Main

Dim fso, f, cmdFile

Dim ln, cmd, pmt, sel, rc

Const ForReading = 1, ForWriting = 2, ForAppending = 8

' When error occured, continue to execute

On Error Resume Next

' Open file

cmdFile = crt.Dialog.Prompt("Enter your cmds filename:", "ExecCmds Script", "cmds.txt" )

Set fso = CreateObject("Scripting.FileSystemObject" )

Set f = fso.OpenTextFile(cmdFile, ForReading )

Do While f.AtEndOfStream <> true

' Read line

ln = f.ReadLine

' Trim blankspace

cmd = Trim(ln)

' Skip blank line and comment lines

If len(cmd) <> 0 And Left(cmd, 1) <> "#" Then

' For debug

' MsgBox("Line: " & cmd)

' Exec command

cmd = cmd & vbCrLf

Crt.Screen.Send cmd

rc = Crt.Screen.WaitForStrings(CliPrompt, CliError, 10)

If (showError = 1 And rc <> 1) Then

' error occured

pmt = "Error occured when exec:" & vbCrLf & cmd & vbCrLf & "Continue?"

sel = msgbox(pmt, vbOKCancel, "Information" )

If sel = vbCancel Then

Exit Do

End If ' rc = vbCancel

End If ' ShowError = 1 And rc <> 1

End If ' len(cmd) <> 0 And ...

Loop

f.Close

End Sub

参考资料

<1> SecureCRT help file

<2> Visual Basic Scripting运行时库参考

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值