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 09-11-2009, 07:59 AM
pn8830's Avatar
pn8830 pn8830 is offline
Registered User
 
Join Date: Jul 2006
Location: Parsippany, NJ
Posts: 71
Send to and log multiple sessions simultaneously

Hello,

I was looking for the solution for my task on this forum but could not find anything that would explain how to do what I need. What I need is to connect to multiple hosts and run couple of commands in them and log output. Sounds pretty simple The issue is that it takes the remote system quite some time to print all the output and if I just loop through hosts with Send/WaitForString and collect data one host at time it takes unacceptable amount of time. The hosts work in the same way so all send/waitforstring are identical for all hosts. Is it possible to do it simultaneously?

Thanks,
Pavel.
Reply With Quote
  #2  
Old 09-11-2009, 09:30 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Pavel,

It is possible to reduce the amount of time necessary to run a script if the connections and commands are performed in a pseudo parallel manner, but this may not be the most reliable solution, and the example script is fairly complex.

I have attached the example script (RunCommandsInParallelTabs(Pseudo)--WriteDataToFile.txt) that you may be able to use to create your own solution to the problem of the script taking so long when working serially.

We have found in testing this script that our computer resources limit us to establishing about 80 connections at a time. Depending on your computer resources, you may find that this number will be less or more.

Does it look like this example script might help you create your own solution?
Attached Files
File Type: txt RunCommandsInParallelTabs(Pseudo)--WriteDataToFile.txt (9.1 KB, 644 views)
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 09-11-2009, 09:50 AM
pn8830's Avatar
pn8830 pn8830 is offline
Registered User
 
Join Date: Jul 2006
Location: Parsippany, NJ
Posts: 71
Thanks for looking into that. It will take me some time to understand what this script actually does but from the first sight I see that it may help. Could you tell me what does (Pseudo) mean in this case and what are the reliability issues you mentioned?

Thanks,
Pavel.
Reply With Quote
  #4  
Old 09-11-2009, 11:38 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Pavel,

The example script allows a process composed of multiple steps to be broken down into the individual steps so that each step can be completed across all of the remote connections rather than having to complete the entire process on one host and then move to the next host. So we serialize the steps rather than the entire process so that the execution of commands can overlap allowing the script to complete more quickly over multiple hosts.

Does this help to explain what I mean by "Pseudo"?

With regards to reliability, I meant that with a script that is as complex as this, handling errors can be difficult. For example, if step 3 in a process consisting of 20 steps is completed successfully on 10 out of 30 remote devices, and fails on remote device 11, deciding what to do and how to accomplish it can be more complex.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #5  
Old 09-11-2009, 02:12 PM
pn8830's Avatar
pn8830 pn8830 is offline
Registered User
 
Join Date: Jul 2006
Location: Parsippany, NJ
Posts: 71
Thank you, that explains much. Though I'm still having difficulty understanding how it works. It looks like function SendToAllTabs is looping through the g_vTabs and using Send/WaitForString technique. It my mind that would wait for execution to complete in one tab, then send command to another tab. It's like if I have command A and command B to be executed on 4 systems then instead of doing A B A B A B A B it does A A A A B B B B. In order to achieve time savings something needs to be executed simultaneously. And so far due to me being new to VBS I fail to understand which steps are run at the same time. It looks like you mentioned that some of commands are overlapping. Is that correct?

In case of UNIX/Linux I normally run the data collection script as a background process. On Windows ... I don't know, I was hoping that SecureCRT framework can provide some means for that.

What I really need to do is to run 2 commands on 8 systems and log so reliability is probably not a concern. Main concern is timing because it affects the decision making point.

Thanks,
Pavel.
Reply With Quote
  #6  
Old 09-11-2009, 04:28 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Pavel,

The simplified form of the SendToAllTabs() method is as follows:
Code:
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function SendToAllTabs(strSendString)
    For Each objTab In g_vTabs     
        objTab.Activate
        objTab.Screen.Send strSendString

        ' Wait for what we've just sent to the remote to be processed before
        ' exiting... this way, we're more likely to know that the remote side
        ' has received the data (since it has now echo'ed it back to us).
        On Error Resume Next
        objTab.Screen.WaitForString strSendString
        On Error Goto 0
    Next
End Function
Note that the objTab.Screen.WaitForString strSendString statement is not waiting for the results of the command that was sent; it's merely waiting to see that the remote system received the command that was sent (and echo'd the command back to SecureCRT). For example, if you manually send the command "ls" to a remote host, you won't be sure that the remote successullfy and completely received the command until "ls" appears on the screen.

Note that (with the exception of Trace Option debugging output, and z/x/ymodem transfer progress updates), SecureCRT only displays on its screen what the remote tells it to display. So we can be guaranteed that the remote received the command if it was able to echo exactly what we sent.

This technique of waiting for a command to be echo'd by the remote helps ensure that the remote has received the command successfully and completely. Then, you can move on to the next host.

It's the WaitForInAllTabs() function that you use, passing in the expected shell prompt as a parameter, to detect when the command has completed in each tab (we're waiting for the shell prompt; not the "ls" command itself, referring to the earlier example I used).

At this point, it becomes obvious that the shell prompt (or at least some portion of it) must be unique from all the command output, and must be the same for all hosts/tabs. Otherwise, our script will hang on one of the tabs waiting for a shell prompt that will never appear.

You could conceptually take out the part of SendToAllTabs() that waits for confirmation that the remote received (and echo'd) the command, but it's a best practice timing wise to make sure each host received the command before moving on to sending the same command to the next host.


By "overlapping", here's a walk-through that I hope will make it more clear for you. Let's say that I have 3 hosts, all connected in tabs. Here's the sequence using SendToAllTabs() and WaitForInAllTabs():

SendToAllTabs "ls" & vbcr
We enter the "For..Next" loop.
  • For Host#1 (Tab#1), the "ls" command is sent, and we wait for evidence that the remote has received the "ls" command by waiting for "ls" to appear on the screen. Once it's found, we know that the "ls" command has been received and is now running on Host#1. We hit the "Next" statement, and we move up to the top of the For..Next loop again.
  • Now, it's Host#2(Tab#2). The "ls" command is sent to Host#2. Note that we haven't waited for evidence that the "ls" command has finished in Host#1 (Tab#1), so it's most likely that both Host#1 and Host#2 will be running "ls" commands simultaneously -- Host#1's "ls" got a head start because the command was sent to it first, but Host#2's "ls" wasn't that far behind, so the "ls" command is running "overlapped", meaning that it's running on both Host#1 and Host#2 at roughly the same time. We hit the "Next statement, and we move up to the top of the For..Next loop again.
  • Now, it's Host#3(Tab#3). The "ls" command is sent to Host#3. Note that we still haven't waited for evidence that the "ls" command has finished in either of the previuos tabs. Consider if the "ls" command takes an average of 10 seconds to complete (we've got a lot of files there ), but it only takes 1 second to send the "ls" command to each tab, then we'll have an instance of "ls" running simultaneously on all 3 hosts (at least for about 7 seconds).

This same concept applies to the WaitForInAllTabs() method. The "ls" command has been sent to all existing connected tabs, so we call WaitForInAllTabs telling it to look for the shell prompt to indicate the command has completed.
WaitForInAllTabs "#", True is called, and we enter the For..Next loop.
  • In Host#1(Tab#1), we wait for evidence that the "ls" command has completed, by looking for the shell prompt. Note that the "ls" command may have already completed in all of the tabs -- but we need to look for evidence of completion by searching for the shell prompt within the output that was sent to each tab as a result of running the "ls" command.
  • Once we find the shell prompt, we move on to the next tab/host (via the For..Next loop) and repeat the process of looking for evidence that the command has completed in the 2nd tab...
  • Then the 3rd tab.


Does this information help paint a clearer picture for you?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #7  
Old 09-14-2009, 08:33 AM
pn8830's Avatar
pn8830 pn8830 is offline
Registered User
 
Join Date: Jul 2006
Location: Parsippany, NJ
Posts: 71
Thank you very much, this explains A LOT!
In my original script I was using crt.Session.log True/False to capture the data and changing crt.Session.logfilename to write to different files. So I guess with the coding in your script I could do objTab.log true/false and do the same thing, right?

Pavel.
Reply With Quote
  #8  
Old 09-14-2009, 10:03 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Pavel,

It would be possible to do what you want, but the functions would need to be modified.

The SendToAllTabs function would need to be modified to enable logging and set the log file name prior to sending the command to the remote device.

The WaitForInAllTabs function would need to disable logging after determining that the output of the command has completed.

Does this help to answer your question?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730

Last edited by rtb; 09-14-2009 at 10:21 AM.
Reply With Quote
  #9  
Old 09-14-2009, 11:03 AM
pn8830's Avatar
pn8830 pn8830 is offline
Registered User
 
Join Date: Jul 2006
Location: Parsippany, NJ
Posts: 71
Thanks, Todd. This helps tremendously.

Pavel.
Reply With Quote
  #10  
Old 09-14-2009, 12:18 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Pavel,

I am glad I could help answer your questions and explain the script.

Feel free to post your success or any additional questions.
__________________
--Todd

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 11:19 PM.