|
![]() |
|
Thread Tools | Rate Thread | Display Modes |
#31
|
|||
|
|||
Hi kgaudineer,
I don't think that you need a completely new script. I would likely add another condition after line 199. For example: Code:
If Instr(strCommand, "copy") > 0 Then ' Take special action ' Perhaps you can build a prompt ' Handle the need to press Enter two times ' Etc. Else ' Proceed normally with rest of code End If |
#32
|
|||
|
|||
Good afternoon rtb,
Thank you for the post... Unfortunately that won't help. These are prompts returned by the switch.... I am thinking it may just be easier to create a new script.. I have tried copying and pasting sections of this vbs script into a new one and that hasn't worked out either... My dilemma is there are several hundred of these switches I need to hit and it looks like this script has a hard time with a dynamic prompts.... Just out of curiosity is there any documentation on the commands used in Secure CRT. I downloaded a VBS book and other than the if, then, else, and case.... this book isn't much help for your VBS script. I did see the VBS FAQ but that's not much help either... I am looking for info on the commands and their arguments. For example... objNewTab.Screen.CurrentColumn -1 leaves me with 2 questions.... What is objNewTab and what does the -1 mean? |
#33
|
||||
|
||||
Hi kgaudineer,
Quote:
Quote:
If you manually type the command all at once, what output do you see? Please post the output exactly as it would appear. If you need to redact sensitive data, replace each redacted character with an "x". Quote:
The scripting manual is a good place to start if you are learning. The variable objNewTab is an object. The internet has a wealth of information on learning object oriented programming concepts. Quote:
Last edited by rtb; 10-09-2014 at 03:32 PM. |
#34
|
|||
|
|||
Good Morning RTB thank you for the reply...
to answer the first question these are the promps when trying to ftp the config In the line below Cisco-2960# is the prompt and copy startup-config tftp: is the command. following the command you must hit return Ciaco-2960#copy startup-config tftp: The line in red below is what is returned after hitting the return key. 10.24.21.117 is the IP of the tftpo server. must hit retunr to move on... Address or name of remote host []? 10.24.21.117 The line below is what is returned after presiing enter. The switch will use its host name as a suggestion for the filename. in all cases we want to keep the host name as the file name and add a .txt to the end of it... Destination filename [Cisco-2960-confg]? After pressing enter for the 3 rd time you swill see the output below. this indicates a successful config file transfer. !! 39344 bytes copied in 0.157 secs (250599 bytes/sec) Cisco-2960# The file I am working with I have commented out lines 215 & 216 and 259 Lines 215 & 216 are: ' Wait for the command to be echo'd back to us. g_objNewTab.Screen.WaitForString strCommand and Line 259 is: strResult = g_objNewTab.Screen.ReadString(strPrompt) The script does look like it will run most of the way through, however are having a problem with the last line feed. There is no more information that needs to be added and all that needs to be done is to just hit the return key. How do we put that as a command in the command file being read in? Also Is there a way to get one log file for each host instead of one log file for every command that is run? This command file has several lines of commands ... |
#35
|
|||
|
|||
Hi kgaudineer,
Thanks for the information. Here is my understanding from what you posted. If you send the command copy startup-config tftp: the Cisco device responds with the following: Address or name of remote host []? 10.24.21.117Do you have to manually enter the IP address or is that automatically populated? After you press Enter, the Cisco device responds with the following: Destination filename [Cisco-2960-confg]?Do you just have to press Enter at this point? |
#36
|
|||
|
|||
Good evening rtb,
following the first command copy startup-config tftp the Cisco switch will respond with: Address or name of remote host []?The IP address 10.24.21.117 needs to be manually entered or in this case its just a separate line in my commands file that is read. After entering the IP address press enter The switch responds with: Destination filename [Cisco-2960-confg]?The switch will automatically use its host name as the config file name. For us this is just fine so there is no need to change anything and we just press the enter key to accept the name as it is shown. |
#37
|
|||
|
|||
Good morning rtb
I had a second thought this morning... Since there are basically only 3 commands that are being used for this task is there a way to comment out the section of the script that reads commands in from a separate file and just hard code the 3 file transfer steps ? My thoughts are trying it this way... copy startup-config tftp 10.24.21.117 waitfor string "#", "?" {enter} OR copy startup-config tftp://10.24.21.117/{variable to construct file name} {enter} waitfor string "#", "?" {enter} waitfor string "#", "?" {enter} |
#38
|
|||
|
|||
Hi kgaudineer,
It seems like your idea would work. Were you able to successfully edit the script to use your idea? |
#39
|
|||
|
|||
Good afternoon rtb,
I have not been successful in editing the script yet. Each time I try I break something else with the script.... My plan was to comment out this section starting at line 100.... ' Now call the ReadDataFromFile() function for the commands file. If Not ReadDataFromFile(g_strCommandsFile, _ g_strComment, _ vCommands, _ nCommandCount, _ nCommentLines) Then DisplayMessage "No commands were found in file: " & vbcrlf & _ vbtab & g_strCommandsFile Exit Sub End If There must be some other dependencies for this section because the error handling and the log file don't work correctly now.... |
#40
|
|||
|
|||
Hi kgaudineer,
There are other dependencies. I am not sure how your script may be different, but in the unmodified script, it is lines 91 to 99 that read in the data from the commands file. The ReadDataFromFile() function definition begins on line 326. You can see that vCommands is an array that is passed by reference when the function is called to read the data from the commands file. After vCommands is populated with the commands to run, it is the foundation of the For Each...Next loop that starts on line 198. I think that rather than try and get rid of the commands file, it may be easier to add in a little code. If you were to use the concept that I suggested initially, you could modify the script to handle many different types of commands. The For Each...Next loop would look something like the following: Code:
For Each strCommand In vCommands If strCommand = "" Then Exit For ' Handle interactive commands. This could have multiple ElseIf statements. ' It would even be possible to include the IP Address in the commands file ' and parse it out in the code below. Commented lines 10-14 and 21 are ' related to this possibility. If Instr(strCommand, "copy") > 0 Then ' Take special action ' If the command was of the following format: ' copy startup-config tftp, 10.10.10.10 ' vData = Split(strCommand, ",") ' Send the command text to the remote ' g_objNewTab.Screen.Send vData[0] & vbcr g_objNewTab.Screen.Send strCommand & vbcr ' Wait "Address or name of remote host []" step g_objNewTab.Screen.WaitForStrings "#", "?" ' Send the IP address ' g_objNewTab.Screen.Send vData[1] & vbcr g_objNewTab.Screen.Send "10.10.10.10" & vbcr ' Wait for "Destination filename [Cisco-2960-confg]" step g_objNewTab.Screen.WaitForStrings "#", "?" ' Press Enter to execute the command g_objNewTab.Screen.Send vbcr Else ' Proceed normally with a portion of the code ' Send the command text to the remote g_objNewTab.Screen.Send strCommand & vbcr ' Wait for the command to be echo'd back to us. g_objNewTab.Screen.WaitForString strCommand End If ' Since we don't know if we're connecting to a cisco switch or a ' linux box or whatever, let's look for either a Carriage Return ' (CR) or a Line Feed (LF) character in any order. vWaitFors = Array(vbcr, vblf) bFoundEOLMarker = False Do ' Call WaitForStrings, passing in the array of possible ' matches. g_objNewTab.Screen.WaitForStrings vWaitFors, 1 ' Determine what to do based on what was found) Select Case g_objNewTab.Screen.MatchIndex Case 0 ' Timed out Exit Do Case 1,2 ' found either CR or LF ' Check to see if we've already seen the other ' EOL Marker If bFoundEOLMarker Then Exit Do ' If this is the first time we've been through ' here, indicate as much, and then loop back up ' to the top and try to find the other EOL ' marker. bFoundEOLMarker = True End Select Loop ' Now that we know the command has been sent to the remote ' system, we'll begin the process of capturing the output of ' the command. Dim strResult ' Use the ReadString() method to get the text displayed ' while the command was runnning. Note that the ReadString ' usage shown below is not documented properly in SecureCRT ' help files included in SecureCRT versions prior to 6.0 ' Official. Note also that the ReadString() method captures ' escape sequences sent from the remote machine as well as ' displayed text. As mentioned earlier in comments above, ' if you want to suppress escape sequences from being ' captured, set the Screen.IgnoreEscape property = True. strResult = g_objNewTab.Screen.ReadString(strPrompt) Dim objFile, strLogFile ' Set the log file name based on the remote host's IP ' address and the command we're currently running. We also ' add a date/timestamp to help make each filename unique ' over time. strLogFile = Replace( _ g_strLogFileTemplate, _ "IPADDRESS", _ g_objNewTab.Session.RemoteAddress) ' Replace any illegal characters that might have been ' introduced by the command we're running (e.g. if the ' command had a path or a pipe in it) strCleanCmd = Replace(strCommand, "/", "[SLASH]") strCleanCmd = Replace(strCleanCmd, "\", "[BKSLASH]") strCleanCmd = Replace(strCleanCmd, ":", "[COLON]") strCleanCmd = Replace(strCleanCmd, "*", "[STAR]") strCleanCmd = Replace(strCleanCmd, "?", "[QUESTION]") strCleanCmd = Replace(strCleanCmd, """", "[QUOTE]") strCleanCmd = Replace(strCleanCmd, "<", "[LT]") strCleanCmd = Replace(strCleanCmd, ">", "[GT]") strCleanCmd = Replace(strCleanCmd, "|", "[PIPE]") strLogFile = Replace(strLogFile, "COMMAND", strCleanCmd) ' Add Time stats to the log file name based on the Template ' defined by the script author. strLogFile = Replace(strLogFile, "YYYY-", Year(Date) & "-") strLogFile = Replace(strLogFile, "-MM-", "-" & NN(Month(Date)) & "-") strLogFile = Replace(strLogFile, "-DD-", "-" & NN(Day(Date)) & "-") strLogFile = Replace(strLogFile, "-hh'", "-" & NN(Hour(Time)) & "'") strLogFile = Replace(strLogFile, "'mm'", "'" & NN(Minute(Time)) & "'") strLogFile = Replace(strLogFile, "'ss", "'" & NN(Second(Time))) Set objFile = g_fso.OpenTextFile(strLogFile, ForAppending, True) ' If you want the command logged along with the results, ' uncomment the next two lines ' objFile.WriteLine "Results of command """ & strCommand & _ ' """ sent to host """ & g_strHost & """: " ' Write out the results of the command and a separator objFile.WriteLine strResult ' Close the log file objFile.Close Next Does this help you move forward in creating your script? |
#41
|
|||
|
|||
Good afternoon rtb,
Thank you very much for the example. This is working out much better than trying to comment out the section. If I understand the explanation correctly. I can continue to add 'Else If' blocks just in case I come across a device that has a new prompt that I am not familiar with.... Is that correct.... |
#42
|
|||
|
|||
Hi kgaudineer,
You are welcome. I am hoping that this discussion will benefit others that want to use this example and read this thread. I can see that my explanation is not very good. Adding additional ElseIf statements to the If...Then...Else condition would allow one to handle other interactive commands. For example: Code:
If Instr(strCommand, "copy") > 0 Then ' Take special action ' If the command was of the following format: ' copy startup-config tftp, 10.10.10.10 ' vData = Split(strCommand, ",") ' Send the command text to the remote ' g_objNewTab.Screen.Send vData[0] & vbcr g_objNewTab.Screen.Send strCommand & vbcr ' Wait "Address or name of remote host []" step g_objNewTab.Screen.WaitForStrings "#", "?" ' Send the IP address ' g_objNewTab.Screen.Send vData[1] & vbcr g_objNewTab.Screen.Send "10.10.10.10" & vbcr ' Wait for "Destination filename [Cisco-2960-confg]" step g_objNewTab.Screen.WaitForStrings "#", "?" ' Press Enter to execute the command g_objNewTab.Screen.Send vbcr ElseIf Instr(strCommand, "<additional interactive command>") > 0 Then ' Take special action for additional interactive command Else ' Proceed normally with a portion of the code ' Send the command text to the remote g_objNewTab.Screen.Send strCommand & vbcr ' Wait for the command to be echo'd back to us. g_objNewTab.Screen.WaitForString strCommand End If If you found another prompt that you needed to handle when trying to use the copy command, then you would need to modify the first If block. I can help explain how to do that, but I would need example output including the new prompt. Did you find a new prompt that you need to handle as a part of the copy command? |
#43
|
|||
|
|||
Using Python Script
Quote:
telnet 1.1.1.1 password: ******** cisco> enable password : ******* Cisco# if we can't get a solution how can I ignore the prompt change. Thanks |
#44
|
|||
|
|||
Hi iabudi,
Thanks for the post. What errors can you get if enable fails? What error do you see if the password is invalid? |
#45
|
|||
|
|||
Python Script
Quote:
but I am running into a new issue where it runs the first command then stops at the prompt and when I stop the script it tells me its stoped at line 399 # Wait for the command to be echo'd back to us. g_objNewTab.Screen.WaitForString(strCommand + "\r\n") The window shows: Router-name# I not sure what is the script looking for? Thanks |
![]() |
Tags |
example script |
Thread Tools | |
Display Modes | Rate This Thread |
|
|