vbscript - Automatic Telnet to cisco switches -


i have many switches backup every night. need create job automatically backup running config.

i using this, how can use list of server ip addresses instead of having repeat code.

option explicit  on error resume next  dim wshshell  set wshshell=createobject("wscript.shell")  wshshell.run "cmd.exe"  wscript.sleep 1000  'send commands window needed - ip , commands need customized  'step 1 - telnet remote ip'  wshshell.sendkeys "telnet 10.1.130.91 23" wshshell.sendkeys ("{enter}") wscript.sleep 1000   'step 2 - issue commands pauses'  wshshell.sendkeys ("password")  wscript.sleep 1000  wshshell.sendkeys ("{enter}")  wscript.sleep 500 wshshell.sendkeys ("enable") wshshell.sendkeys ("{enter}") wscript.sleep 500  wshshell.sendkeys ("password") wshshell.sendkeys ("{enter}") wscript.sleep 500  wshshell.sendkeys ("terminal length 0") wshshell.sendkeys ("{enter}") wscript.sleep 500  wshshell.sendkeys ("show running-config") wshshell.sendkeys ("{enter}") wscript.sleep 500  wshshell.sendkeys ("copy run tftp://10.1.211.53/file1.xls") wshshell.sendkeys ("{enter}") wscript.sleep 500   wshshell.sendkeys ("10.1.211.53") wshshell.sendkeys ("{enter}") wscript.sleep 500  wshshell.sendkeys ("file1.xls") wshshell.sendkeys ("{enter}") wscript.sleep 2000   'step 3 - exit command window  wshshell.sendkeys "exit" wshshell.sendkeys ("{enter}") wscript.sleep 500 wshshell.sendkeys "exit"  wshshell.sendkeys ("{enter}") 

here go. create file named ciscoips.txt ip address carriage return after each one. avoid spaces @ end of records.

10.2.2.23 10.4.5.23 10.5.7.23 

the ip list should in same folder vbscript, can change editing "stripfile = "ciscoips.txt" @ top of script. let me know if have issues.

option explicit dim wshshell, stripfile, objfso, objfile, ipaddress  stripfile = "ciscoips.txt"  on error resume next  set wshshell = createobject("wscript.shell") set objfso = createobject("scripting.filesystemobject")  const forreading =   1 const forwriting =   2 const forappending = 8 const readonly =     1  set objfile = objfso.opentextfile(stripfile, forreading)  until objfile.atendofstream   ipaddress = objfile.readline   'wscript.echo ipaddress   wshshell.run "cmd.exe"    wscript.sleep 1000    'send commands window needed - ip , commands need customized    'step 1 - telnet remote ip'    wshshell.sendkeys "telnet " & ipaddress & " 23"    wshshell.sendkeys ("{enter}")   wscript.sleep 1000    'step 2 - issue commands pauses'    wshshell.sendkeys ("password")    wscript.sleep 1000    wshshell.sendkeys ("{enter}")    wscript.sleep 500   wshshell.sendkeys ("enable")   wshshell.sendkeys ("{enter}")   wscript.sleep 500    wshshell.sendkeys ("password")   wshshell.sendkeys ("{enter}")   wscript.sleep 500    wshshell.sendkeys ("terminal length 0")   wshshell.sendkeys ("{enter}")   wscript.sleep 500    wshshell.sendkeys ("show running-config")   wshshell.sendkeys ("{enter}")   wscript.sleep 500    wshshell.sendkeys ("copy run tftp://" & ipaddress & ".xls")   wshshell.sendkeys ("{enter}")   wscript.sleep 500    wshshell.sendkeys ("10.1.211.53")   wshshell.sendkeys ("{enter}")   wscript.sleep 500    wshshell.sendkeys ("file1.xls")   wshshell.sendkeys ("{enter}")   wscript.sleep 2000    'step 3 - exit command window    wshshell.sendkeys "exit"   wshshell.sendkeys ("{enter}")   wscript.sleep 500   wshshell.sendkeys "exit"   wshshell.sendkeys ("{enter}") loop  objfile.close 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -