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-01-2013, 10:09 AM
mbaBrickman mbaBrickman is offline
Registered User
 
Join Date: May 2013
Posts: 3
Opening Multiple sessions through the command prompt

I'm tiring to open multiple tabs of the same session and run a different script for each session. I'm using the code below to open the sessions can call the scripts for each session

WshShell.run "C:\CRT\SecureCRT.exe /T /s Payroll /SCRIPT C:\brickman\crt_scripts\PayrollScripts\Branch671.vbs /s Payroll /SCRIPT C:\brickman\crt_scripts\PayrollScripts\Branch673.vbs /s Payroll /SCRIPT C:\brickman\crt_scripts\PayrollScripts\Branch674.vbs /s Payroll /SCRIPT C:\brickman\crt_scripts\PayrollScripts\Branch675.vbs /s Payroll /SCRIPT C:\brickman\crt_scripts\PayrollScripts\Branch676.vbs /s Payroll /SCRIPT C:\brickman\crt_scripts\PayrollScripts\Branch678.vbs /s Payroll /SCRIPT C:\brickman\crt_scripts\PayrollScripts\Branch681.vbs /s Payroll /SCRIPT C:\brickman\crt_scripts\PayrollScripts\Branch780.vbs /s Payroll /SCRIPT C:\brickman\crt_scripts\PayrollScripts\Branch781.vbs /s Payroll /SCRIPT C:\brickman\crt_scripts\PayrollScripts\Branch788.vbs /s Payroll /SCRIPT C:\brickman\crt_scripts\PayrollScripts\Branch789.vbs /s Payroll /SCRIPT C:\brickman\crt_scripts\PayrollScripts\Branch790.vbs /s Payroll /SCRIPT C:\brickman\crt_scripts\PayrollScripts\Branch791.vbs /s Payroll /SCRIPT C:\brickman\crt_scripts\PayrollScripts\Branch792.vbs", 0, true

When i do this i get multiple tabbed sessions but each session runs the last script in the code Branch792.vbs

how do i get each session to call its own script?

thanks.
Reply With Quote
  #2  
Old 05-01-2013, 11:51 AM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Greetings mbaBrickman,

I don't see any syntax problems with the command. The length of the command makes it a little challenging to read, but I don't think that's the problem.

If your scripts do not contain sensitive data, can you post Branch674.vbs and Branch791.vbs?

If they do contain sensitive data (username, password, specific hostname, etc.) then please send the scripts to support@vandyke.com with subject Forum Thread 11004, or send email and request a secure upload account so that you can upload them for us to review.
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #3  
Old 05-01-2013, 12:54 PM
mbaBrickman mbaBrickman is offline
Registered User
 
Join Date: May 2013
Posts: 3
I replaced the user name and password in the scripts with "username" and "password". The only difference between all the scripts is one line with the branch number. It takes about 3 hours for one branch to run so accounting has been opening a new session for each branch so they can run it all at the same time when i run the script that creates new sessions for all these scrips the branch number entered is 792 for all sessions.

Branch657.vbs

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

crt.Screen.Synchronous = True

TodaysDate = Right("0" & DatePart("m", Date), 2) _
& "/" & Right("0" & DatePart("d", Date), 2) _
& "/" & Right(DatePart("yyyy", Date), 2)


Sub Main

crt.Screen.Send chr(13)
crt.Screen.WaitForString chr(27) & "[24;79H" & chr(27) & "[19;66H" & chr(27) & "[1;2H" & TodaysDate & chr(27) & "[1;36HC O I N S" & chr(27) & "[19;66H" & chr(27) & "[24;79H" & chr(27) & "[24;79H" & chr(27) & "[3;1H" & chr(27) & "[K" & chr(27) & "[4;1H" & chr(27) & "[K" & chr(27) & "[5;1H" & chr(27) & "[K" & chr(27) & "[7;1H" & chr(27) & "[K" & chr(27) & "[8;1H" & chr(27) & "[K" & chr(27) & "[9;1H" & chr(27) & "[K" & chr(27) & "[11;1H" & chr(27) & "[K" & chr(27) & "[12;1H" & chr(27) & "[K" & chr(27) & "[13;1H" & chr(27) & "[K" & chr(27) & "[14;1H" & chr(27) & "[K" & chr(27) & "[16;1H" & chr(27) & "[K" & chr(27) & "[17;1H" & chr(27) & "[K" & chr(27) & "[18;1H" & chr(27) & "[K" & chr(27) & "[19;1H" & chr(27) & "[K" & chr(27) & "[24;79H" & chr(27) & "[19;66H" & chr(27) & "[6;23H" & chr(14) & "lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk" & chr(27) & "[7;23Hx" & chr(15) & " COINS Version 7 (10.7c2.43) " & chr(14) & "x" & chr(27) & "[8;23Hx" & chr(27) & "[8;32H" & chr(15) & "November 26, 2012" & chr(27) & "[8;57H" & chr(14) & "x" & chr(27) & "[9;23Hmqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj" & chr(27) & "[19;66H" & chr(27) & "[13;29Hlqqqqqqqqqqqqqqqqqqqqqqk" & chr(27) & "[14;29Hx" & chr(15) & " Password: " & chr(27) & "[4m " & chr(27) & "[m " & chr(14) & "x" & chr(27) & "[15;29Hmqqqqqqqqqqqqqqqqqqqqqqj" & chr(27) & "[19;66H" & chr(27) & "[14;43H" & chr(27) & "[24;79H" & chr(27) & "[24;1H" & chr(15) & "Enter data or press F4 to end." & chr(27) & "[24;79H" & chr(27) & "[14;43H"
crt.Screen.Send chr(13)
crt.Screen.WaitForString chr(27) & "[24;1H" & chr(27) & "[K" & chr(27) & "[24;79H" & chr(27) & "[14;43H " & chr(27) & "[24;79H" & chr(7) & chr(27) & "[22;1H" & chr(27) & "[7mInvalid password." & chr(27) & "[m" & chr(27) & "[13;29H" & chr(27) & "[K" & chr(27) & "[14;29H" & chr(27) & "[K" & chr(27) & "[15;29H" & chr(27) & "[K" & chr(27) & "[22;18H" & chr(27) & "[10;26H" & chr(14) & "lqqqqqqqqqqqqqqqqqqqqqqqqqqqk" & chr(27) & "[11;26Hx" & chr(15) & " Enter User ID: " & chr(27) & "[4m " & chr(27) & "[m " & chr(14) & "x" & chr(27) & "[12;26Hmqqqqqqqqqqqqqqqqqqqqqqqqqqqj" & chr(27) & "[22;18H" & chr(27) & "[24;1H" & chr(27) & "[11;45H" & chr(27) & "[24;79H" & chr(27) & "[24;1H" & chr(15) & "Enter data or press F4 to end." & chr(27) & "[24;79H" & chr(27) & "[11;45H"
crt.Screen.Send "username" & chr(13)
crt.Screen.WaitForString chr(27) & "[m" & chr(27) & "[22;1H" & chr(27) & "[K" & chr(27) & "[11;52H" & chr(27) & "[24;1H" & chr(27) & "[K" & chr(27) & "[24;79H" & chr(27) & "[11;45Hhamp.ni " & chr(27) & "[24;79H" & chr(27) & "[24;79H" & chr(27) & "[13;29H" & chr(14) & "lqqqqqqqqqqqqqqqqqqqqqqk" & chr(27) & "[14;29Hx" & chr(15) & " Password: " & chr(27) & "[4m " & chr(27) & "[m " & chr(14) & "x" & chr(27) & "[15;29Hmqqqqqqqqqqqqqqqqqqqqqqj" & chr(27) & "[24;79H" & chr(27) & "[24;1H" & chr(27) & "[14;43H" & chr(27) & "[24;79H" & chr(27) & "[24;1H" & chr(15) & "Enter data or press F4 to end." & chr(27) & "[24;79H" & chr(27) & "[14;43H"
crt.Screen.Send "password" & chr(13)
crt.Screen.Send "7" & chr(13)
crt.Screen.Send "6" & chr(13)
crt.Screen.Send "674" & chr(13)
crt.Screen.Send chr(13)
crt.Screen.Send chr(13)
crt.Screen.Send chr(13)
crt.Screen.Send chr(13)
End Sub

Branch791.vbs

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

crt.Screen.Synchronous = True


TodaysDate = Right("0" & DatePart("m", Date), 2) _
& "/" & Right("0" & DatePart("d", Date), 2) _
& "/" & Right(DatePart("yyyy", Date), 2)

Sub Main
crt.Screen.Send chr(13)
crt.Screen.WaitForString chr(27) & "[24;79H" & chr(27) & "[19;66H" & chr(27) & "[1;2H" & TodaysDate & chr(27) & "[1;36HC O I N S" & chr(27) & "[19;66H" & chr(27) & "[24;79H" & chr(27) & "[24;79H" & chr(27) & "[3;1H" & chr(27) & "[K" & chr(27) & "[4;1H" & chr(27) & "[K" & chr(27) & "[5;1H" & chr(27) & "[K" & chr(27) & "[7;1H" & chr(27) & "[K" & chr(27) & "[8;1H" & chr(27) & "[K" & chr(27) & "[9;1H" & chr(27) & "[K" & chr(27) & "[11;1H" & chr(27) & "[K" & chr(27) & "[12;1H" & chr(27) & "[K" & chr(27) & "[13;1H" & chr(27) & "[K" & chr(27) & "[14;1H" & chr(27) & "[K" & chr(27) & "[16;1H" & chr(27) & "[K" & chr(27) & "[17;1H" & chr(27) & "[K" & chr(27) & "[18;1H" & chr(27) & "[K" & chr(27) & "[19;1H" & chr(27) & "[K" & chr(27) & "[24;79H" & chr(27) & "[19;66H" & chr(27) & "[6;23H" & chr(14) & "lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqk" & chr(27) & "[7;23Hx" & chr(15) & " COINS Version 7 (10.7c2.43) " & chr(14) & "x" & chr(27) & "[8;23Hx" & chr(27) & "[8;32H" & chr(15) & "November 26, 2012" & chr(27) & "[8;57H" & chr(14) & "x" & chr(27) & "[9;23Hmqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj" & chr(27) & "[19;66H" & chr(27) & "[13;29Hlqqqqqqqqqqqqqqqqqqqqqqk" & chr(27) & "[14;29Hx" & chr(15) & " Password: " & chr(27) & "[4m " & chr(27) & "[m " & chr(14) & "x" & chr(27) & "[15;29Hmqqqqqqqqqqqqqqqqqqqqqqj" & chr(27) & "[19;66H" & chr(27) & "[14;43H" & chr(27) & "[24;79H" & chr(27) & "[24;1H" & chr(15) & "Enter data or press F4 to end." & chr(27) & "[24;79H" & chr(27) & "[14;43H"
crt.Screen.Send chr(13)
crt.Screen.WaitForString chr(27) & "[24;1H" & chr(27) & "[K" & chr(27) & "[24;79H" & chr(27) & "[14;43H " & chr(27) & "[24;79H" & chr(7) & chr(27) & "[22;1H" & chr(27) & "[7mInvalid password." & chr(27) & "[m" & chr(27) & "[13;29H" & chr(27) & "[K" & chr(27) & "[14;29H" & chr(27) & "[K" & chr(27) & "[15;29H" & chr(27) & "[K" & chr(27) & "[22;18H" & chr(27) & "[10;26H" & chr(14) & "lqqqqqqqqqqqqqqqqqqqqqqqqqqqk" & chr(27) & "[11;26Hx" & chr(15) & " Enter User ID: " & chr(27) & "[4m " & chr(27) & "[m " & chr(14) & "x" & chr(27) & "[12;26Hmqqqqqqqqqqqqqqqqqqqqqqqqqqqj" & chr(27) & "[22;18H" & chr(27) & "[24;1H" & chr(27) & "[11;45H" & chr(27) & "[24;79H" & chr(27) & "[24;1H" & chr(15) & "Enter data or press F4 to end." & chr(27) & "[24;79H" & chr(27) & "[11;45H"
crt.Screen.Send "username" & chr(13)
crt.Screen.WaitForString chr(27) & "[m" & chr(27) & "[22;1H" & chr(27) & "[K" & chr(27) & "[11;52H" & chr(27) & "[24;1H" & chr(27) & "[K" & chr(27) & "[24;79H" & chr(27) & "[11;45Hhamp.ni " & chr(27) & "[24;79H" & chr(27) & "[24;79H" & chr(27) & "[13;29H" & chr(14) & "lqqqqqqqqqqqqqqqqqqqqqqk" & chr(27) & "[14;29Hx" & chr(15) & " Password: " & chr(27) & "[4m " & chr(27) & "[m " & chr(14) & "x" & chr(27) & "[15;29Hmqqqqqqqqqqqqqqqqqqqqqqj" & chr(27) & "[24;79H" & chr(27) & "[24;1H" & chr(27) & "[14;43H" & chr(27) & "[24;79H" & chr(27) & "[24;1H" & chr(15) & "Enter data or press F4 to end." & chr(27) & "[24;79H" & chr(27) & "[14;43H"
crt.Screen.Send "password" & chr(13)
crt.Screen.Send "7" & chr(13)
crt.Screen.Send "6" & chr(13)
crt.Screen.Send "791" & chr(13)
crt.Screen.Send chr(13)
crt.Screen.Send chr(13)
crt.Screen.Send chr(13)
crt.Screen.Send chr(13)
End Sub
Reply With Quote
  #4  
Old 05-01-2013, 02:19 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
Thanks. There are multiple problems:
  • SecureCRT does not currently support /SCRIPT on a per session basis.
  • Using crt.screen.Send sends to the active tab, so it's not tab safe.
  • Using crt.Screen.Send and crt.screen.Send back to back, without WaitForString in between, inevitably leads to problems.
An immediately available alternative would be to split up the wsh call to start SecureCRT sessions without /T.
WshShell.run "C:\CRT\SecureCRT.exe /s Payroll /SCRIPT C:\brickman\crt_scripts\PayrollScripts\Branch671.vbs

WshShell.run "C:\CRT\SecureCRT.exe /s Payroll /SCRIPT C:\brickman\crt_scripts\PayrollScripts\Branch673.vbs

WshShell.run "C:\CRT\SecureCRT.exe /s Payroll /SCRIPT C:\brickman\crt_scripts\PayrollScripts\Branch674.vbs
Since /SCRIPT cannot be called multiple times, you need to find another way to activate the script.

A simple way might be:
  • Make a single, tab safe script named BranchScript.vbs
  • Have BranchScript.vbs read an argument that's sent to it, and based on that argument, send a specific line. Now you don't need to maintain so many scripts - you just need one script.
  • Instead of starting SecureCRT with a specific script, like this:
    WshShell.run "SecureCRT.exe /s Payroll /SCRIPT Branch674.vbs

    do something more general and pass in an argument, like this (pseudocode):
    foreach nBranchNum in ("674, 681, 781, 791, etc...")
    WshShell.run "SecureCRT.exe /SCRIPT "BranchScript.vbs" /ARG nBranchNum /T /S Payroll

Tab safety: you'll probably want to use GetScriptTab, which returns the tab or tiled session window from which the script was started.[/QUOTE] This function will be useful because each script will know which session started it. This will help you keep track of which tab to send to or read from.

I recognize that this is just an overview, and there isn't a quick solution. Fixing the back to back Sends, and making it script safe, the script will have little in common with what it is now when you're finished. It might be easier to start over with a script like: Read Data From Separate Hosts/Commands File And Log To Individual Files .
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
  #5  
Old 05-02-2013, 07:29 AM
mbaBrickman mbaBrickman is offline
Registered User
 
Join Date: May 2013
Posts: 3
Thanks this information was helpful
Reply With Quote
  #6  
Old 05-02-2013, 12:54 PM
miked's Avatar
miked miked is offline
Registered User
 
Join Date: Feb 2004
Posts: 2,040
mbaBrickman,

There is a similar discussion happening in another VanDyke forum thread. It's not exactly the same question as yours but there may be some useful information.
__________________
Mike
VanDyke Software
Technical Support
[http://www.vandyke.com/support]
Reply With Quote
Reply

Tags
scripts


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 04:07 AM.