Solved

ProCurve Switch Backup Script

Posted on 2014-04-28
4
1,002 Views
Last Modified: 2014-04-28
I am trying to get the following script to work in our environment and the author is unresponsive.
Here is the original article:
http://www.experts-exchange.com/Hardware/Networking_Hardware/Switches/A_10799-Backing-up-Configuration-settings-HP-ProCurve-switches'.html

 I have setup the directory and scripts as follows:
BackupScript.vbs, this contains the meat of the scripting and should work, but when I run it I get an error about a " ' " on line 14 Char 30...
*Note, thie orig article does not say what type of script to save the file as, it may or may not be a visual basic script...

Backups Directory, this is where the SwitchBackup.cfg should end up
Then I have both the tftpd32.exe and its ini file, and the TST10.exe programs for the script to call...
ListSwitch.txt has a list of my switch IP addresses in it for the script to loop through.

here is the code for the BackupScript.vbs, what am i missing here:

CODE:
Set IPTftpHost = "192.168.1.185" 'This is where the TFTP IP is declared. 
Set 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 """.\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 ""Username"""& vbCrLf & _'Waiting for Username Prompt
		"SEND ""admin\m"""& vbCrLf & _'Sending 'admin' text string
		"WAIT ""Password"""& vbCrLf & _'Waiting for Continue
		"SEND ""mypassword\m"""& vbCrLf & _'Sending 'admin' text string
		"WAIT ""SW"""& vbCrLf & _'Wait for SW(This is for the switch name)
		'"SEND "" \m"""& vbCrLf & _'Sending nothing(Press any key to continue)
		'"SEND "" \m"""& vbCrLf & _'Sending nothing(Press any key to continue)
		"SEND ""copy run tftp "& IPTftpHost & " " & fName & ".cfg"""& vbCrLf & _'This is the 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.
Loop 'End loop
f.WriteLine("taskkill /IM tftpd32.exe")'We kill the TFTP server
f.WriteLine("MOVE *.cfg .\Backups")'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.

Open in new window


Thanks for any help...
0
Comment
Question by:speeDemon
  • 2
4 Comments
 
LVL 17

Accepted Solution

by:
jburgaard earned 500 total points
ID: 40027693
AFAIK you can’t use the continuation character (underscore) with comments. Every line that has a comment must start with a single quote.
So I would try remove the comments from continuation lines.
0
 

Expert Comment

by:jdouthit
ID: 40028111
We use a program Solarwinds to backup all of our switches and routers.  It is called CatTools.

http://www.solarwinds.com/kiwi-cattools.aspx
0
 
LVL 1

Author Closing Comment

by:speeDemon
ID: 40028314
Perfect here is the final script:
The ListSwitch.txt file needs to have the Switch IP on one line, then the Switch Name on the next then start over...
Example:
192.168.1.1
Switch1
192.168.1.2
Switch2



<CODE>
IPTftpHost="192.168.1.185" '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 """.\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.
      fSwitchName = 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 & _
            "WAIT ""Username:"""& vbCrLf & _
            "SEND ""admin\m"""& vbCrLf & _
            "WAIT ""Password"""& vbCrLf & _
            "SEND ""mypassword\m"""& vbCrLf & _
            "SEND "" \m"""& vbCrLf & _
            "WAIT """& fSwitchName &""""& vbCrLf & _
            "SEND ""copy run tftp "& IPTftpHost & " RunningConfig_" & Year(Date) & Right("0" & Month(Date),2) & Right("0" & Day(Date),2) & "_" & fSwitchName & ".cfg"""& vbCrLf & _
            "WAIT """& fSwitchName &""""& vbCrLf & _
            "SEND "" \m"""& vbCrLf & _
            "SEND ""logout\m"""& vbCrLf & _
            "WAIT ""log out"""& vbCrLf & _
            "SEND ""y\m"""& vbCrLf & _
            "SEND ""n\m"""& vbCrLf & _
            "")
      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.
Loop 'End loop
f.WriteLine("taskkill /IM tftpd32.exe")'We kill the TFTP server
f.WriteLine("MOVE *.cfg .\Backups")'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.
</CODE>

Thanks for the help
0
 
LVL 17

Expert Comment

by:jburgaard
ID: 40028410
Thank YOU
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Wifi(LAN) GW being picked up 2 34
Eigrp Router 5 46
Exit a vb6 apps when a calling it apps closes 15 33
Network Config 9 53
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now