Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1255
  • Last Modified:

ProCurve Switch Backup Script

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
speeDemon
Asked:
speeDemon
  • 2
1 Solution
 
jburgaardCommented:
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
 
jdouthitCommented:
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
 
speeDemonAuthor Commented:
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
 
jburgaardCommented:
Thank YOU
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now