SecureCRT下的批命令脚本
2006-05-06 20:50
176 查看
下面的脚本是在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运行时库参考
这个脚本在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运行时库参考
相关文章推荐
- securecrt使用vbs脚本向多个tabs窗口发送带变量的命令
- secureCRT上telnet自动登陆并周期发送命令的脚本
- SecureCRT中用vbs脚本批量执行unix命令
- 选择MySQL数据库的命令以及PHP脚本下的操作方法
- SecureCRT常用命令 (三)
- 我使用过的Linux命令之dot - 绘制DOT语言脚本描述的图形
- SecureCRT脚本编写,解决arm时间设置问题
- linux命令之-----ping命令简介以及检查同一网段ip地址是否网络联通的脚本
- shell脚本--cut命令
- 脚本命令
- Hadoop之HDFS的Shell脚本命令总结
- java Runtime.getRuntime().exec 调用系统脚本/命令注意事项
- java调用perl脚本中cat和more命令的执行结果
- Linux Source命令及脚本的执行方式解析
- powershell的一个脚本,用来测试命令的
- SecureCRT录制和添加自动登录脚本
- rsync 命令详细解释并附加备份脚本
- SecureCRT-----命令大全
- shell命令, shell脚本linux操作
- SecureCRT的sz/rz工具包,linux下没有sz和rz命令