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-12-2010, 08:31 AM
burakq burakq is offline
Registered User
 
Join Date: May 2010
Posts: 1
How to stop script1 from script2

two scripts at the same time for two different tabs.
One is to continously type something with a sleep interval.
Second one is to monitor for an output in the terminal and if matches, to stop the script1 and sendkey for the first tab

TAB1 - Script 1 - Sendkey - Sleep - Sendkey
TAB2 - Script 2 - Waitforstring - Stop Script 1 - SendKey for first tab

I couldn't figure out how to stop the script what command if possible?

Any ideas?
Reply With Quote
  #2  
Old 05-12-2010, 09:16 AM
WesR WesR is offline
Registered User
 
Join Date: Mar 2005
Location: USA
Posts: 149
The only way I've found to do something like this is with an external file that script 2 monitors and exits depending on that file. Script 1 would simply change something in the file, or create/delete the file, depending on how you prefer to implement it.
Reply With Quote
  #3  
Old 05-12-2010, 11:57 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Hello burakq,

The method WesR describes will work. Another method would be to use an environment variable for the scripts to communicate between each other.

As an example, here is code you could run in the first tab (or window). It continuously generates information until it detects that an environment variable is no longer set to "RUNNING".
Code:
' CommunicateBetweenTwoScriptsUsingEnvVar(Script1).vbs
'
' DESCRIPTION:
'   Example of how to use an Environment Variable to pass information between
'   two separate script instances running in SecureCRT.
'  
'   Works in combination with another example script:
'     CommunicateBetweenTwoScriptsUsingEnvVar(Script2).vbs
'
'   - This script (Script 1) runs in say, Tab#1, and is launched first.
'

Dim g_shell, g_env
Set g_shell = CreateObject("WScript.Shell")
Set g_env   = g_shell.Environment("Volatile")

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub Main()

    ' Set up an initial state for the common environment Variable that we'll
    ' be using between both scripts:
    g_env("INTER_SCRIPT_COMM") = "RUNNING"
    
    ' While connected to a remote machine, do some work.  For example...
    Do
        crt.Screen.Send "ps -eaf | grep vshelld" & vbcr
        crt.Sleep 1000
        
        ' Check to see if the
        If g_env("INTER_SCRIPT_COMM") <> "RUNNING" Then Exit Do
    Loop
    
End Sub
Script 2 will wait for an event to occur. For example, suppose you want to know when root tries to login with a bad password. When this is detected, it will set the environment variable to something other than "RUNNING".
Code:
' CommunicateBetweenTwoScriptsUsingEnvVar(Script2).vbs
'
' DESCRIPTION:
'   Example of how to use an Environment Variable to pass information between
'   two separate script instances running in SecureCRT.
'  
'   Works in combination with another example script:
'     CommunicateBetweenTwoScriptsUsingEnvVar(Script1).vbs
'
'   - This script (Script 2) runs in say, Tab#2, and is launched after Script#1.
'

Dim g_shell, g_env
Set g_shell = CreateObject("WScript.Shell")
Set g_env   = g_shell.Environment("Volatile")

'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub Main()

    ' Issue a remote command that produces desired output to the SecureCRT
    ' screen.
    crt.Screen.Send "tail -f /var/log/messages | grep vshelld" & vbcr
    
    ' Scan screen for something that indicates the first script (Script1) should
    ' quit.  Wait for an indication (just an example, here) of a root attempting
    ' to authenticate to VShell with a bad password
    crt.Screen.WaitForString "password for user root rejected"
    
    ' Now, set value of common environment variable so that script 1 will exit:
    g_env("INTER_SCRIPT_COMM") = "STOP"
    
End Sub
One possible benefit of the environment variable approach is that the environment is in memory instead of on the hard disk, so if there's going to be a lot of inter-script communication performance might be a little better using an environment variable.
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #4  
Old 05-12-2010, 12:21 PM
WesR WesR is offline
Registered User
 
Join Date: Mar 2005
Location: USA
Posts: 149
Nice!

I think I'm still rooted in that one window, one script mentality.
Reply With Quote
  #5  
Old 05-12-2010, 12:33 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Thanks WesR,

You reminded me of one other thing I wanted to mention. You can use the scripts either in two tabs in the same window, or two separate windows.
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
Reply


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 08:31 AM.