Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 05-06-2014, 10:26 AM
sprocket sprocket is offline
Registered User
 
Join Date: May 2014
Posts: 2
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.
Reply With Quote
  #2  
Old 05-06-2014, 12:07 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi sprocket,

Thanks for the post.
Quote:
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.
Can you provide more details about this?

If the script is finished, what is not happening until what program is closed?
Quote:
Also can you link to a syslog server to enable logging when successful?
Are you asking if you can get SecureCRT to log to a syslog server?

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
This is found in the Scripting / Script Objects Reference / Arguments Object chapter.

Does this help?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 05-07-2014, 03:07 AM
sprocket sprocket is offline
Registered User
 
Join Date: May 2014
Posts: 2
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.




Quote:
Originally Posted by rtb View Post

Can you provide more details about this?

If the script is finished, what is not happening until what program is closed?

Are you asking if you can get SecureCRT to log to a syslog server?
Reply With Quote
  #4  
Old 05-07-2014, 08:40 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi sprocket,

Thanks for the information.
Quote:
Yes I would like to log to a syslog server from SecureCRT.
This is not currently possible from SecureCRT. I have created a feature request in our SecureCRT enhancement database to add the ability to log to a syslog server. Should we add this ability in the future, we will post to this thread.

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#post37294
Would 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.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #5  
Old 05-08-2014, 02:31 PM
krillik krillik is offline
Registered User
 
Join Date: May 2013
Posts: 13
Quote:
Originally Posted by sprocket View Post
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.
EDIT: I did read the whole thread and this is one way to solve your issue so securecrt can move on to the next IP. You would of course just have to change the code that sends commands. There may be an easier way than mine, but this is the route I chose to take. I hope it helps!

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.
Reply With Quote
Reply

Tags
automate , logging , silent


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 07:21 AM.