Batch Command Script under securecrt

Source: Internet
Author: User
The following script runs in securecrt and is written in vbs. Put all the configuration commands in a text file, and then use the test script to execute these commands to simplify the configuration process during the test.
This script is successfully debugged on securecrt version 4.0 (build 358.

Modify the cliprompt, clierror, showerror, and other constants as needed.
Cliprompt is the CLI command prompt
Clierror is an error message displayed when a configuration error occurs. It is used to identify the command execution result.
Showerror indicates whether a prompt box is displayed when an error occurs.
 
When executing the command, you are prompted to enter a command list file name and then execute all the commands in the file. The local file name is cmds.txt.
The format of the command list file is very simple. Each Command is placed in a single line.
If the first character of a line is "#", it indicates that this line is a comment line and is skipped during execution.
If a row contains no characters or only spaces, it is considered as a blank line and skipped during execution.
 
I hope to help you.

# $ 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, encrypted file
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
Export File = CRT. Dialog. Prompt ("Enter your cmds filename:", "execcmds script", "cmds.txt ")
Set FSO = Createobject ("scripting. FileSystemObject ")
Set F = FSO. opentextfile (encoding file, 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

References
<1> securecrt Help File
<2> Visual Basic Scripting Runtime Library Reference

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.