#1
|
|||
|
|||
Empty files using objFile.Write
Hello,
I have edited one of the scripts found on this site to save configs from a Cisco device. It works fine " most of the time". The problem I am having is that some of the text files saved have no data, resulting in empty files. But it isnt consistent. It also does not happen for the same device twice. If I have 15 devices in file used for reading, 12 may work correctly while the other 3 may have no data in the written file. Normally with other scripts I have used, I have the crt.Screen.Synchronous = True set. But with this script, when it is enabled, all files are empty, meaning no data is written. Because of this, I am assuming the problem I am having has something to do with the synchronous data being intermittently missed. Below is a sample copy of the script. Please review and let me know if there is something misconfigured that is causing my problem. Thanks. Note: I have commented out a message box line and the synchronous line that I use for testing. #$language = "VBScript" #$interface = "1.0" Sub Main ' crt.Screen.Synchronous = True Dim fso Set fso = CreateObject("Scripting.FileSystemObject") Const ForReading = 1 Const ForWriting = 2 Dim strSwIP Dim strSwName Set objFile1 = fso.OpenTextFile("C:\switches.txt", ForReading, False) Dim fil Set fil = fso.OpenTextFile("C:\switches.txt") While Not fil.AtEndOfStream line = fil.ReadLine strSwIP = Split(line, ";")(0) strSwName = Split(line, ";")(1) Set objFile3 = fso.OpenTextFile("C:\" & strSwName & ".txt", ForWriting, True) crt.Screen.Send strSwIP & VbCr crt.Screen.WaitForString "Password:" crt.Screen.Send "password" & VbCr If (crt.Screen.WaitForString(">", 3)) Then crt.Screen.Send "en" & VbCr crt.Screen.WaitForString "Password:" crt.Screen.Send "password" & VbCr else End If crt.Screen.Send "term len 0" & VbCr crt.Screen.WaitForString "#" crt.Screen.Send "sh run" & VbCr crt.Screen.WaitForString VbCr strResult = crt.Screen.ReadString(strSwName & "#") ' MsgBox strResult objFile3.Write strResult crt.Screen.Send "exit" & VbCr crt.Screen.WaitForString "closed by foreign host" Wend fil.Close End Sub |
#2
|
|||
|
|||
Hi ddnllc,
I don't see anything particularly wrong with the script other than the not setting Synchronous equal to True. If you include the following line prior to the first Send() statement, and uncomment the line where you message box the results of the ReadString() line, do you see anything in the message box? PHP Code:
|
#3
|
|||
|
|||
Quote:
|
#4
|
|||
|
|||
Hi ddnllc,
Thanks for the update. I think I understand what you are saying, but I don't have your devices to test against, so this is something that you will need to troubleshoot. With that said, I do have some suggestions for troubleshooting this issue. Line 4 has a Send() which is not followed by a WaitForString(). This may work most of the time, but can fail. PHP Code:
PHP Code:
PHP Code:
PHP Code:
|
#5
|
|||
|
|||
Thank you!!!
Quote:
|
#6
|
|||
|
|||
You are welcome ddnllc. I am glad I could help.
I wanted to point you to one additional suggestion. I mentioned using a case statement to handle authentication. Here is an example that may help you make your script more robust: http://forums.vandyke.com/showpost.p...63&postcount=2 |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Display Modes | Rate This Thread |
|
|