Windows scripts to output Show commands to a file?

Unanswered Question
Sep 25th, 2008

I have a routine task to look for "10/half" ports and CRC error ports for over 100 switches. I'm hoping I can execute a script from my Windows PC to do it, for example every Monday, and have all the outputs exported to a file. Can anyone tell me how to do it?

Here is my current manual steps for each switch:

a. telnet to the switch

b. username and password login

c. sh int status | include half

d. sh int | include CRC

Thanks a lot


I have this problem too.
0 votes
  • 1
  • 2
  • 3
  • 4
  • 5
Overall Rating: 0 (0 ratings)
Collin Clark Thu, 09/25/2008 - 05:35

You could do this pretty easily with SecureCRT and a vbScript. If you have SecureCRT I could post a script that could do it.

gwhuang5398 Thu, 09/25/2008 - 10:26

Thanks a lot. I'd love to see your scripts as a sample. I wasn't thinking about SecureCRT but I do have it.

Thanks again.

Collin Clark Thu, 09/25/2008 - 10:50

Here it is. You need to create a file under C:\ (or change the location in the script) named HostIP.txt that lists your hosts (by IP). An example follows-

Here's the script.

<font size="2"></p><p># $language = "VBScript"</p><p># $interface = "1.0"</p><p>'==================================================================</p><p>'Date: September 25, 2008</p><p>'==================================================================</p><p>'Description: Check on half-duplex interfaces and CRC errors</p><p>' The script reads IP address from a file called C:\HostIP.txt</p><p>' And Connects to each switch via the SecureCRT and places</p><p>' the Log information into a text files named after the IP address</p><p>' of each Switch IE:</p><p>' The Log file are located in a folder which the user inputs at the</p><p>' Start of the script.</p><p>' For devices it cannot connect to it logs the IP address into another</p><p>' Text file called NoConnect.txt located into the same folder.</p><p>'==================================================================</p><p>'VARIABLES</p><p>Dim FSO, Shell, Windir, Runservice, oFile, oFile1</p><p>Const ForReading = 1</p><p>Const ForWriting = 2</p><p>Const ForAppending = 8</p><p>Set FSO = CreateObject("scripting.filesystemobject")</p><p>Set Shell = CreateObject("WScript.Shell")</p><p>Set SwitchIP = FSO.opentextfile("C:\HostIP.txt", ForReading, False)</p><p>Set objDictionary = CreateObject("Scripting.Dictionary")</p><p>Set objSc = crt.Screen</p><p>Set objD = crt.Dialog</p><p>Set objSe = crt.Session</p><p>Set objW = crt.Window</p><p>Logfiles = objD.Prompt("Enter folder name and Path to save Log files In.","Folder Name & Path","C:\LogFiles")</p><p></p><p>If FSO.FolderExists(Logfiles) Then</p><p>Else</p><p>FSO.CreateFolder(Logfiles)</p><p>End IF</p><p></p><p>While Not SwitchIP.atEndOfStream</p><p>IP = SwitchIP.Readline()</p><p></p><p>' connect To host On port 23</p><p>On Error Resume Next</p><p>objse.Connect "/TELNET "&IP&" 23"</p><p></p><p>If ( objse.connected ) Then</p><p>objsc.Synchronous = True</p><p>objse.logfilename = Logfiles&""&IP&".Log"</p><p>objse.Log(True)</p><p>objSc.WaitForString "assword:"</p><p>objSc.Send "YourVTYPassword" & vbCr</p><p>objsc.WaitForString">"</p><p>objSc.Send "enable" & vbCr</p><p>objSc.WaitForString "assword:"</p><p>objSc.Send "YourEnablePassword" & vbCr</p><p>objSc.WaitForString "#"</p><p>crt.Screen.Send vbCr</p><p>' Enter config mode</p><p>crt.Screen.WaitForString "#"</p><p>crt.Screen.Send "config terminal" & vbCr</p><p>crt.Screen.WaitForString "#"</p><p>' Check half duplex interfaces</p><p>crt.Screen.Send "sh int status | include half " & vbCr</p><p>crt.Screen.WaitForString "#"</p><p>' Check for CRC errors</p><p>crt.Screen.Send "sh int | include CRC" & vbCr</p><p>crt.Screen.WaitForString "#"</p><p>crt.Screen.Send "q" & vbCr</p><p></p><p>objse.Log(False)</p><p>objSc.Synchronous = False</p><p>objSE.Disconnect</p><p></p><p>Else</p><p></p><p>Set Tempfile = FSO.OpenTextFile(Logfiles&"\NoConnect.txt",ForAppending, True)</p><p>TempFile.writeline "Could Not Connect to " & IP</p><p>TempFile.Close()</p><p>End If</p><p>Wend</p><p></font>

Hope that helps.


This Discussion