#1
|
|||
|
|||
automated backup / arguments and logging
Looking at using SecureCrt to automate our Sonicwall router backups. I have got a script sort of working, automatic log in and backup but have a few issues and not sure if I am doing it correct or have go off track. Using some arguments would be good to make my scripts easier to reproduce for all of our Sonicwalls.
I wish to schedule the script to run during the night on a server with no user interaction. The main problem I have is once the script is run and device disconnects, SecureCrt stays open and nothing will happen until the program is closed. Also can you link to a syslog server to enable logging when successful? My example is for one backup, but could add multiple lines for each one. I have a batch file that runs: SecureCRT.exe /SCRIPT C:\Sonicwall1.vbs /SSH2 /L user 172.16.28.1 Sonicwall1.vbs Sub Main Dim host crt.Screen.WaitForString "User:" crt.Screen.Send "admin" & chr(13) crt.Screen.WaitForString "Password:" crt.Screen.Send "******" & chr(13) crt.Screen.Send "export preferences ftp 172.16.200.199 user password Sonicwall1.exp" & chr(13) crt.Screen.Send "exit" & chr(13) End Sub If I can get this to work silently how do I modify this to use an argument in the script for the save file name (.exp). Then I will only need to modify and copy the command in the batch file. |
#2
|
|||
|
|||
Hi sprocket,
Thanks for the post. Quote:
If the script is finished, what is not happening until what program is closed? Quote:
As to using arguments, here is an example from the Help file that illustrates how one can use arguments: Code:
#$language = "VBScript" #$interface = "1.0" Sub Main() ' This script should be run by SecureCRT that has two ' /ARG parameters for a hostname and port, for example: ' ' SecureCRT.exe /ARG myhostname /ARG 5555 ' Detect lack of arguments. If crt.Arguments.Count <> 2 Then MsgBox "This script requires hostname and port arguments" Exit Sub End If ' MsgBox "Connecting to hostname: " & crt.Arguments(0) MsgBox "Connecting to port: " & crt.Arguments(1) ... End Sub Does this help? |
#3
|
|||
|
|||
Hi
What I was thinking of was to have a batch file like below with multiple devices, but once the first line is run, SecureCRT stays open and doesn't move to the next line until SecureCRT is closed. SecureCRT.exe /SCRIPT C:\Sonicwall1.vbs /SSH2 /L user 172.16.28.1 SecureCRT.exe /SCRIPT C:\Sonicwall2.vbs /SSH2 /L user 172.16.29.1 SecureCRT.exe /SCRIPT C:\Sonicwall2.vbs /SSH2 /L user 172.16.30.1 Yes I would like to log to a syslog server from SecureCRT. |
#4
|
|||
|
|||
Hi sprocket,
Thanks for the information. Quote:
I searched the internet, and found that there are some VBScript examples out there that may be of use in logging to a syslog server. You may want to investigate this as a workaround. As to your goal, do you need to have multiple scripts that are run individually from the command-line via batch file? If not, we have a single script example that may be of use to you. You can find it at the following location: https://forums.vandyke.com/showthrea...7294#post37294Would this work for you? Another thing to try would be to close SecureCRT in your existing script. You could disconnect your session in the script and then use the Quit() method of the Application object to close SecureCRT. |
#5
|
|||
|
|||
Quote:
I dont know if this is exactly what you want to do. But here is an idea. I have a DCCS I need to login to and change my PW regularly. I have to login to 73 different DCCS. I hate changing passwords manually, so I created a script to grab the IPs that I need to connect to, open them in a new tab one by one, run the commands, and read the "completed" message. Anything that fails will show in a message box(that can be changed to a text file). So this MIGHT help you. Possibly have a batch file to run this command: SecureCRT.exe /SCRIPT C:\SonicwallBackup.vbs Then edit that file instead of the batch file. Create an array for all your ips that you need to get into. Hopefully they all use the same user and password, if not that can be modified. Here is the code that I use(keep in mind I have the ips loaded from a different class file, so this would need to be modified a bit to your tastes): Code:
Sub DCCS call Include("C:\Scripts\PWChange\DCSip.class.vbs") Dim oDCCS Set oDCCS = New cDCCS oDCCS.Load arrIPList = oDCCS.DCCSiplist Set oDCCS = Nothing Continue End Sub Sub Continue For Each ip in arrIPList 'If abort = 1 Then Exit For chgDCCS(ip) Next If UBound(arrPWErrors) >= 0 Then Dim herp, derp derp = uBound(arrPWErrors) + 1 herp = Join(arrPWErrors," | ") Msgbox "Script ended. Errors on " & derp & " IP(s): " & herp & ". Please change these manually." Else Msgbox "Script ended, no errors." End if End Sub Sub chgDCCS(content) Dim a, b, objCurrentTab, nIndex, objTab crt.Session.ConnectInTab("/FIREWALL=" & strFirewall & " /telnet " & content) For x = 1 to crt.GetTabCount Set objTab = crt.GetTab(x) Select Case objTab.Caption Case content Set objCurrentTab = crt.GetTab(x) End Select Next objCurrentTab.Activate objCurrentTab.Screen.WaitForString "5500" crt.Screen.Synchronous = True objCurrentTab.Screen.Send "ACT-USER::" & strUser & ":xx::" & strPW & ";" & Chr(13) objCurrentTab.Screen.WaitForStrings "M" a = objCurrentTab.Screen.ReadString(";") If InStr(a, "DENY") Then Abort(content) objCurrentTab.Session.Disconnect objCurrentTab.Close Else crt.Sleep 1000 objCurrentTab.Screen.Send "ED-CHAN:::xx::CRALM=OFF,MJALM=OFF,MNALM=OFF,NAEVT=OFF,CONDSCHED=OFF,REPTSCHED=OFF,PMSCHED=OFF,SYSMSG=OFF;" & Chr(13) crt.Sleep 2000 objCurrentTab.Screen.Send "ED-SECU-PID::" & strUser & ":xx::" & strPW & ":" & strNewPW & "," & strNewPW & ";" & Chr(13) objCurrentTab.Screen.WaitForStrings "M" b = objCurrentTab.Screen.ReadString(";") If InStr(b, "DENY") Then Abort(content) objCurrentTab.Session.Disconnect objCurrentTab.Close Else objCurrentTab.Screen.Send "CANC-USER::" & strUser & ":xx;" & Chr(13) objCurrentTab.Session.Disconnect objCurrentTab.Close End If End If End Sub Sub Abort(ip) ReDim Preserve arrPWErrors(k) arrPWErrors(k) = ip k = k + 1 End Sub Last edited by krillik; 05-08-2014 at 02:39 PM. |
![]() |
Tags |
automate , logging , silent |
Thread Tools | |
Display Modes | Rate This Thread |
|
|