Cisco Support Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Community Member

Windows scripts to output Show commands to a file?

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

Gary

3 REPLIES

Re: Windows scripts to output Show commands to a file?

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

Community Member

Re: Windows scripts to output Show commands to a file?

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.

Re: Windows scripts to output Show commands to a file?

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-

192.168.1.5

192.168.6.5

192.168.9.5

Here's the script.

# $language = "VBScript"

# $interface = "1.0"

'==================================================================

'Date: September 25, 2008

'==================================================================

'Description: Check on half-duplex interfaces and CRC errors

' The script reads IP address from a file called C:\HostIP.txt

' And Connects to each switch via the SecureCRT and places

' the Log information into a text files named after the IP address

' of each Switch IE:192.168.0.2.Log

' The Log file are located in a folder which the user inputs at the

' Start of the script.

' For devices it cannot connect to it logs the IP address into another

' Text file called NoConnect.txt located into the same folder.

'==================================================================

'VARIABLES

Dim FSO, Shell, Windir, Runservice, oFile, oFile1

Const ForReading = 1

Const ForWriting = 2

Const ForAppending = 8

Set FSO = CreateObject("scripting.filesystemobject")

Set Shell = CreateObject("WScript.Shell")

Set SwitchIP = FSO.opentextfile("C:\HostIP.txt", ForReading, False)

Set objDictionary = CreateObject("Scripting.Dictionary")

Set objSc = crt.Screen

Set objD = crt.Dialog

Set objSe = crt.Session

Set objW = crt.Window

Logfiles = objD.Prompt("Enter folder name and Path to save Log files In.","Folder Name & Path","C:\LogFiles")

If FSO.FolderExists(Logfiles) Then

Else

FSO.CreateFolder(Logfiles)

End IF

While Not SwitchIP.atEndOfStream

IP = SwitchIP.Readline()

' connect To host On port 23

On Error Resume Next

objse.Connect "/TELNET "&IP&" 23"

If ( objse.connected ) Then

objsc.Synchronous = True

objse.logfilename = Logfiles&"\"&IP&".Log"

objse.Log(True)

objSc.WaitForString "assword:"

objSc.Send "YourVTYPassword" & vbCr

objsc.WaitForString">"

objSc.Send "enable" & vbCr

objSc.WaitForString "assword:"

objSc.Send "YourEnablePassword" & vbCr

objSc.WaitForString "#"

crt.Screen.Send vbCr

' Enter config mode

crt.Screen.WaitForString "#"

crt.Screen.Send "config terminal" & vbCr

crt.Screen.WaitForString "#"

' Check half duplex interfaces

crt.Screen.Send "sh int status | include half " & vbCr

crt.Screen.WaitForString "#"

' Check for CRC errors

crt.Screen.Send "sh int | include CRC" & vbCr

crt.Screen.WaitForString "#"

crt.Screen.Send "q" & vbCr

objse.Log(False)

objSc.Synchronous = False

objSE.Disconnect

Else

Set Tempfile = FSO.OpenTextFile(Logfiles&"\NoConnect.txt",ForAppending, True)

TempFile.writeline "Could Not Connect to " & IP

TempFile.Close()

End If

Wend

Hope that helps.

1723
Views
0
Helpful
3
Replies
CreatePlease to create content