This tutorial will go through the steps required to write a script that will back up the configuration settings of a HP-ProCurve switch.
You will need to get the following things to follow this tutorial:
Telnet Scripting Tool e.g. TST10.exe
Any text editing tool
TFTP Server(I am using TFTP 32 for this tutorial)
List of IP addresses for your switches
1. Installing and starting TFTP32
First thing we need to do is download the software from their web page: "http://tftpd32.jounin.net/tftpd32_download.html
". We need to download "tftpd32 standard edition (zip)". Create a new folder and name it "SwitchesBackup" open the zip file and copy the .exe and .ini files into the folder since that's the only files we need for TFTP.
Now start the tftpd32.exe and you will be prompted with a Windows firewall warning. We need to allow it to work. After that the program should start up:
2. Getting TST10
Next we will need TST10.exe for the Telnet connection. You can get this file at: http://jerrymannel.com/blog/2008/11/11/telnet-scripting-tool-aka-tst10exe/
scroll down and you will find the file as a .exe or zip; after downloading it place the .exe in the folder "SwitchesBackup".
3. Writing the Script
Now that we have both executables in the folder called "SwitchesBackup". We can continue and start making the script.
First of all, we need to get the IP from the TFTP32 program place the ip in "InserIPHERE".
Then we need to change %PATHHERE% at line 32 to the path you want to save the .cfg files at (the configuration backups)
I've written explanations after every line in the code to show you what the script does:
IPTftpHost = "InsertIPHERE" 'This is where the IP is declared.
NameCMDFile = "Runbackup.cmd" 'This is the name of the command file that will be created.
Set fso = CreateObject("Scripting.FileSystemObject") 'Scripting.FileSystemObject declare.
Set f = fso.OpenTextFile(NameCMDFile, 2, True) 'Creating/opening the command file.
Set listFile = fso.OpenTextFile("ListSwitch.txt") 'This is the list of IP addresses of your switches'
Set shell = CreateObject("WScript.Shell") 'WScript shell declare
shell.Run """C:\Program Files (x86)\Tftpd32\tftpd32.exe""", 1, false' We start the TFTP server
Do while not listFile.AtEndOfStream 'This is the start of the loop for the file with the list of switches.
fName = listFile.ReadLine()'Fname is the line read from the file.
Set filetxt = fso.CreateTextFile(fName & ".txt", True)'We create a textfile with the IP of the switch
filetxt.WriteLine("" & _
fName & " 23" & vbCrLf & _'Connection string
"WAIT ""continue"""& vbCrLf & _'Waiting for Continue
"SEND "" \m"""& vbCrLf & _'Sending nothing(Press any key to continue)
"SEND ""copy run tftp "& IPTftpHost & " " & fName & ".cfg"""& vbCrLf & _'This is de important part, this is where you copy RUN over TFTP to your server
"WAIT ""SW"""& vbCrLf & _'Wait for SW(This is for the switch name)
"SEND "" \m"""& vbCrLf & _'Send nothing
"SEND ""logout\m"""& vbCrLf & _'Send the logout command
"WAIT ""log out"""& vbCrLf & _'Wait for log out y/n
"SEND ""y\m"""& vbCrLf & _'Send yes
"SEND ""n\m"""& vbCrLf & _'Send no(this must be done on some switches)
"")'We write the telnet commands to the .txt
filetxt.Close'We close the filestream.
f.WriteLine("tst10 /r:" & fName & ".txt /m")'We write the command to the CMD file.
f.WriteLine("DEL """ & fName & """.txt")'After that we write the delete command to the CMD file.
f.WriteLine("taskkill /IM tftpd32.exe") 'We kill the TFTP server
f.WriteLine("MOVE *.cfg %PATH HERE%")'We move all files with .cfg to another location.
f.close'We close the file stream.
shell.Run NameCMDFile, 1, true'We run the CMD file.
fso.deletefile(NameCMDFile)'When it's all done we delete the CMD file.
Now that we have the script, start it and you will see it making back-ups of your RUN configuration.
I hope you found this article helpful. And since this is my first article if you have any tips or suggestions please say so!