Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 08-24-2017, 10:25 AM
ashehata ashehata is offline
Registered User
 
Join Date: Aug 2017
Posts: 15
Stop Logon script

Hello,

I would like to know if there's any SecureCRT command syntax to be used in order to stop "Logon script" or any running scripts then enable it again when my script finish. Because when I run my script, I get the following error and I have to uncheck it manually.



Reply With Quote
  #2  
Old 08-24-2017, 10:50 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi ashehata,

I am not sure I fully understand the issue. Are you saying in the same session where you have a logon script configured, you are trying to run another script, via the Script menu (Run option) in SecureCRT?

If so, what does your logon script do? Why is it still running?

If you believe it should be completed, is Cancel available from the Script menu? (If so, what error does it indicate the logon script is hanging/erroring on?)
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 08-25-2017, 11:03 AM
ashehata ashehata is offline
Registered User
 
Join Date: Aug 2017
Posts: 15
Hello Brenda,

Well, I have a script that I run it via the script menu (run option) but at the same time that I have login script which has username and password of devices that I connect to and I used the option logon script as showed in the image above that it's checked. But the problem is, that my script which I run it via the script menu, it has its own username and password to login to the devices. When I run that script. I get the following error.



So I have to go to session option, then uncheck the options of "Logon script" in order to run my script then I have to check it again after running my script.

So my question is there's ant way to include a command into my script which I run it via the script menu that disable the option of the running script of the "logon script" then I enable it again at the end of my script to start working after running my script?


I hope that I clarified my question and feel free to ask me if there's anything still unclear.
Reply With Quote
  #4  
Old 08-25-2017, 01:01 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi ashehata,

The sequence of events is still unclear.

There is not presently any mechanism in SecureCRT that can cancel any other running scripts (from within a script).

However, for the more specific scenario you seem to be relaying (disabling Logon script option in saved sessions), there could be a possibility.

In the script (the one you run from Script menu), are you opening the saved sessions (where Logon script is enabled) using crt.Session.Connect() (or crt.Session.ConnectInTab()) with the /S option?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 08-25-2017, 01:51 PM
ashehata ashehata is offline
Registered User
 
Join Date: Aug 2017
Posts: 15
Hello Brenda,

Sorry for any inconvenience.

Yes, I use crt.Session.ConnectInTab(). Kindly check the below scripts

Part from The script that I run via script menu with run option

Code:
        for x in range (1, rows):

            # Telnet to the junp off server
            tab = crt.Session.ConnectInTab("/ssh2 /L #####/PASSWORD ######")


            #Sync
            tab.Activate()
            tab.Screen.Synchronous = True
            
            # Tab Name
            tab.Caption = Circuits[x]
            
            # Telnet to IGW
            tab.Screen.WaitForString("$")
            tab.Screen.Send("telnet" + ' ' + IPs[x])
            tab.Screen.Send("\n")
            tab.Screen.WaitForString("login:")
            tab.Screen.Send(username)
            tab.Screen.Send("\n") 
            tab.Screen.WaitForString("Password:")
            tab.Screen.Send(password)
            tab.Screen.Send("\n")
            

            # A check if the username or password wrong
            if tab.Screen.WaitForString("login:", 1):       
               tab.Screen.Send("\n")
               while tab.Screen.WaitForString("login:", 15):
                    username = 'wrong'
                    password = 'wrong'
                    credential = user_credential(username, password)
                    username = credential[0]
                    password = credential[1]
                    tab.Screen.Send(username)
                    tab.Screen.Send("\n") 
                    tab.Screen.WaitForString("Password:")
                    tab.Screen.Send(password)
                    tab.Screen.Send("\n")


            # Monitor Section
            tab.Screen.Synchronous = False
            tab.Screen.Send("\n")
            tab.Screen.WaitForString(">")
            tab.Screen.Send("monitor interface" + " " + Interfaces[x] + "\n")

The script which is running on "Logon script"


Code:
#$language = "VBScript"
#$interface = "1.0"

Sub main

Dim user,pass,result,name,row

' Put Here your Username and your Password
user = "#####" '<------------------------------------------------------Here
pass = "#####" '<------------------------------------------------------Here
TNTuser = "####" '<------------------------------------------------------TNT username Here
TNTpass = "#####" '<------------------------------------------------------TNT password Here


crt.Screen.Synchronous = True

result = crt.Screen.WaitForStrings("Username :", "ttyp", "login:", "User:", "Telnet password:","Username:","Password:", 30)
Select Case result
	
	Case 1 'ERX Router
		crt.Screen.Send  user & VbCr
		
		
		crt.Screen.WaitForString "Password :", 20
		crt.Screen.Send ####& VbCr
		
		crt.Screen.WaitForString ">", 20
		crt.Screen.Send "enable" & VbCr
		
		If crt.Screen.WaitForString ("Password:",20) = True Then crt.Screen.Send "####" & vbCr
			
		
		If crt.Screen.WaitForStrings(">","#",20) = 1 Then
			crt.Screen.Send "enable" & VbCr
			crt.Screen.WaitForString "Password:", 20
			crt.Screen.Send "####" & VbCr		
		End If
		
'		crt.Screen.WaitForString "#", 20
'		crt.Screen.Send "terminal width 512" & VbCr
		
	Case 2 'M Router
		crt.Screen.WaitForString "login:", 10
		crt.Screen.Send ####& VbCr
		
		crt.Screen.WaitForString "Password:", 10
		crt.Screen.Send #####& VbCr 
		
	Case 3 'ISAM
		
		CheckString = crt.Screen.Get (1,1,crt.Screen.CurrentRow,crt.Screen.Rows)
		
		If InStr(1,CheckString,"ttyp",1) > 0 Then
			crt.Screen.Send ####& VbCr
			
			crt.Screen.WaitForString "Password:", 10
			crt.Screen.Send ####& vbCr
		Else
			crt.Screen.Send "#####" & VbCr
			
			crt.Screen.WaitForString "password:", 20
			crt.Screen.Send "#####" & vbCr
		End If
				
		
      Case Else
 	      MsgBox "UnKnown Device", vbOKOnly

End Select
  
  ' turn off synchronous mode to restore normal input processing
  crt.Screen.Synchronous = False 

End Sub

Last edited by ashehata; 08-25-2017 at 01:55 PM.
Reply With Quote
  #6  
Old 08-26-2017, 11:10 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi ashehata,

You are using ConnectInTab() but not with a session reference, with an ad hoc connection. That means you have the logon script configured in the Default Session.

The simplest solution is to disable the Logon script option in Default Session (making sure to apply the change to Default Session only).
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #7  
Old 08-28-2017, 11:39 AM
ashehata ashehata is offline
Registered User
 
Join Date: Aug 2017
Posts: 15
Hello Brenda,

Thanks for your helping and assistance.

This solution worked but I had another issue that the logon script was not working with my saved sessions but I solved it by enabling the logon script option in the group of saved sessions.

Last edited by ashehata; 08-28-2017 at 11:41 AM.
Reply With Quote
  #8  
Old 08-28-2017, 11:41 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi ashehata,

I am glad to hear the issue is resolved.

For anyone that reads this post that is not aware of it, there is another tip on our website explaining how to make changes to a subset of *all sessions*. That is functionality that has been available since SecureCRT 6.2.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply

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:32 PM.