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 12-19-2008, 09:43 AM
sfchtm sfchtm is offline
Registered User
 
Join Date: Nov 2008
Posts: 14
Senddata.js

First of all, I'm not a computer guy, I'm an admin guy so if I say something wrong please forgive my ignorance. I perform several redundant task in CRT that this little script has made so simple, but I suppose that is it's purpose. My question is, is there a way to run it twice, or inside itself? Can I access different two different text files at different prompts after a single command? If this does not make since I can get really specific about the commands and prompts and such…
Reply With Quote
  #2  
Old 12-19-2008, 10:15 AM
kbarnette kbarnette is offline
VanDyke Technical Support
 
Join Date: Aug 2007
Posts: 587
Hi sfchtm,

I will need a little more information to understand exactly what it is you are looking to do.

Can you provide the script you are running?

What version of CRT are you using?
Version information can be found in the 'Help/About CRT...' dialog.
Reply With Quote
  #3  
Old 12-19-2008, 11:18 AM
sfchtm sfchtm is offline
Registered User
 
Join Date: Nov 2008
Posts: 14
Hope this is what you need...Thanks

Version 4.1.6 (build 251)

# $language = "JScript"
# $interface = "1.0"

// Open the file c:\temp\file.txt, read it line by line sending each
// line to the server. Note, to run this script successfully you may need
// to update your script engines to ensure that the filesystemobject runtime
// is available.

function main()
{
var fso, f, r;
var ForReading = 1, ForWriting = 2;

fso = new ActiveXObject("Scripting.FileSystemObject");
f = fso.OpenTextFile("c:\\temp\\file.txt", ForReading);

crt.Screen.Synchronous = true;

var str;
while ( f.AtEndOfStream != true )
{
str = f.Readline();
str += "\015" ;
crt.Screen.Send( str );

// wait for the prompt before continuing with the next send.
//
crt.Screen.WaitForString( "prompt$" );
}
};

I use several different text files depending on the task. What I want to do is run it again while one is already running. Or perhaps loop them would be a better expression. I have a task where I give privileges or access to schedules to individuals. There is a list of approximately 80 schedules ( it is constantly updated) and the list of individuals varies from day to day. What I have been doing is typing a txt file of the individuals names. Enter the privileges menu enter the name of the schedule then execute the script to enter all the names. What I would like to do is execute the script to enter the name of the schedule then the names of the individuals then the next schedule then the names again then the next schedule…

Thanks for your help and I hope I don't sound too ignorant.
Reply With Quote
  #4  
Old 12-19-2008, 05:56 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 971
Quote:
Originally Posted by sfchtm
What I would like to do is execute the script to enter the name of the schedule then the names of the individuals then the next schedule then the names again then the next schedule…
It looks like your task might involve "nested loops". In other words, it sounds like you have a list of schedules, and for each of the schedules, you want to iterate through a list of names and do whatever is needed to provide those names with access to the schedule.

You mentioned having two files; is one file the existing file with the list of names, and the other file the list of schedules?

If that's the case, you should be able to open the schedules file, and begin iterating over each item in the schedules file. Within your schedule-iterating loop, you would then open the names file, and begin a loop iterating over each name.

In pseudo code, this might look something like the following:
Code:
scheduleFile = fso.OpenTextFile(strScheduleFilePath)
while ( scheduleFile.AtEndOfStream != true )
{
    strCurrentSchedule = scheduleFile.Readline();
    
    // Now, do the work that needs to be done on the remote to signal that
    // the schedule change nees to happen; 
    
    ... <-- Fill in the blanks here with what you know needs to happen now
    
    // Once you know that the remote is ready to receive the new names,
    // open up the name file and iterate over each of the lines found
    // in the name file
    nameFile = fso.OpenTextFile(strNameFilePath);
    while ( nameFile.AtEndOfStream != true )
    {
        strCurrentName = nameFile.Readline();
        // Now that you have the name from the line that was just read
        // from the name file, send it to the remote as you normally
        // would.
        
        ... <-- Fill in the blanks here with what you know needs to happen now
    }
    
    // When we get here, we'll need to close the name file, and perform any
    // steps needed on the remote system in order to get it ready for the
    // next schedule.
    nameFile.Close( );
    
    ... <-- fill in the blanks here with what you know needs to happen now
}
Does this information help to explain how you might achieve your goal?

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #5  
Old 05-15-2009, 01:39 PM
sfchtm sfchtm is offline
Registered User
 
Join Date: Nov 2008
Posts: 14
Still not working???

I was pulled away to another task for a while but now I'm back. I still haven't got this thing to work. It tells me there is no } at the end. Can someone take a look and tell me what is wrong?

# $language = "JScript"
# $interface = "1.0"

function main()

{
crt.Screen.Send("^priv\r")

var fso, scheduleFile, nameFile;
var ForReading = 1, ForWriting = 2;
fso = new ActiveXObject("Scripting.FileSystemObject");

scheduleFile = fso.OpenTextFile("C:\\Application Data\\Van Dyke Technologies\\CRT\\Config\\Sessions\\Clinics.txt", ForReading);
while ( scheduleFile.AtEndOfStream != true )
{
strCurrentSchedule = scheduleFile.Readline();

crt.Screen.Synchronous = true;

var str;
while ( f.AtEndOfStream != true )
{
str = f.Readline();
str += "\015" ;
crt.Screen.Send( str );

// wait for the prompt before continuing with the next send.
crt.Screen.WaitForString("Select HOSPITAL LOCATION NAME:")

nameFile = fso.OpenTextFile("C:\\Application Data\\Van Dyke Technologies\\CRT\\Config\\Sessions\\Staff.txt", ForReading);
while ( nameFile.AtEndOfStream != true )
{
strCurrentName = nameFile.Readline();

f = fso.OpenTextFile("C:\\Application Data\\Van Dyke Technologies\\CRT\\Config\\Sessions\\Staff.txt", ForReading);

crt.Screen.Synchronous = true;

var str;
while ( f.AtEndOfStream != true )
{
str = f.Readline();
str += "\015" ;
crt.Screen.Send( str );

// wait for the prompt before continuing with the next send.

crt.Screen.WaitForString( "Select PRIVILEGED USER:" );

}

nameFile.Close( );

crt.Screen.WaitForString("Select HOSPITAL LOCATION NAME:")

}
Reply With Quote
  #6  
Old 05-15-2009, 02:19 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 971
sfchtm,
  • You've got a mismatch between the number of opening '{' characters and closing '}' characters. Go through your code and make sure that each opening '{' character has a corresponding '}' in the appropriate place. You've got 5 '{'s and only 2 '}'s. This is why the script interpreter is currently complaining.
  • The earlier sample code I posted only included two "While" statements. Your code has 4. It's not clear why you added the 2 additional loops.
  • The following lines don't seem to make any sense because your code doesn't show any place where you have opened a file for reading via a variable named "f" before attempting to actually read from it:

    Code:
    while ( f.AtEndOfStream != true )
    {
        str = f.Readline();
  • It appears that you are opening the "name" file twice... once using a variable "f", and another time using a variable "nameFile".


--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #7  
Old 06-08-2009, 08:21 AM
sfchtm sfchtm is offline
Registered User
 
Join Date: Nov 2008
Posts: 14
still not sure what I'm doing?

So is this any better? and if so why does it not work? PLEASE HELP!

# $language = "JScript"
# $interface = "1.0"

function main()

{
crt.Screen.Send("^priv\r")

var fso, scheduleFile, nameFile;
var ForReading = 1, ForWriting = 2;
fso = new ActiveXObject("Scripting.FileSystemObject");

crt.Screen.Synchronous = true;
scheduleFile = fso.OpenTextFile("C:\\Application Data\\Van Dyke Technologies\\CRT\\Config\\Sessions\\Clinics.txt", ForReading)
while ( scheduleFile.AtEndOfStream != true )

{
strCurrentSchedule = scheduleFile.Readline();
{

str += "\015" ;
crt.Screen.Send( str );


// Now, do the work that needs to be done on the remote to signal that
// the schedule change needs to happen;

crt.Screen.WaitForString("Select HOSPITAL LOCATION NAME:")
}
// Once you know that the remote is ready to receive the new names,
// open up the name file and iterate over each of the lines found
// in the name file

nameFile = fso.OpenTextFile("C:\\Application Data\\Van Dyke Technologies\\CRT\\Config\\Sessions\\Staff.txt", ForReading);

{

while ( nameFile.AtEndOfStream != true )
strCurrentName = nameFile.Readline();

// Now that you have the name from the line that was just read
// from the name file, send it to the remote as you normally
// would.
{
str += "\015" ;
crt.Screen.Send( str );
crt.Screen.WaitForString( "Select PRIVILEGED USER:" );
}
// When we get here, we'll need to close the name file, and perform any
// steps needed on the remote system in order to get it ready for the
// next schedule.

nameFile.Close( );
}
crt.Screen.WaitForString("Select HOSPITAL LOCATION NAME:")
}
};

Last edited by sfchtm; 06-08-2009 at 08:27 AM.
Reply With Quote
  #8  
Old 06-08-2009, 12:39 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 971
For starters, it seems that the correct "while" loop syntax has been lost in your code since the original example code was provided. In your newest code, you have some stray "{" and "}" characters that don't seem to match up with any of your 'while' loops.

Here's the basics of my original post made back in December, 2008. I've removed instructional comments in order to more clearly show the syntax of the while loops, so you can see how the {s and }s should be placed (there really should only be 4 of these total (two {s and two }s) in your entire script):

Code:
scheduleFile = fso.OpenTextFile(strScheduleFilePath)
while ( scheduleFile.AtEndOfStream != true )
{
    strCurrentSchedule = scheduleFile.Readline();  
    //...

    nameFile = fso.OpenTextFile(strNameFilePath);
    while ( nameFile.AtEndOfStream != true )
    {
        strCurrentName = nameFile.Readline();
        //...
    }
    
    nameFile.Close( );
    //...  
}
Notice that for every "while" statement, there is exactly one opening curly brace that starts the 'while' loop, and one closing curly brace that ends the while loop. Matching up {} characters to start and end a while loop in JScript is essential to proper script operation.

Notice also that the body of each "while" loop is indented 4 spaces, to make it easier to see the start and end of the loop and to clearly indicate which lines of code belong in the loop. This indentation is optional, but very helpul in reading and maintaining code.

With respect to helping you resolve the problem and get to a solution, it will be nearly impossible to help find out what's wrong with your script code without details concerning the behavior you are seeing.

Can you provide details as to what happens when you attempt to run your script?

Do any messages appear?

Does anything get sent to the remote system?

What does your SecureCRT terminal screen show when you are running your script?

What does the SecureCRT terminal screen show when you do this manually, and how does the output from manually performing this task differ from the output you see on the SecureCRT terminal screen when you run your script?

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #9  
Old 06-09-2009, 01:32 PM
sfchtm sfchtm is offline
Registered User
 
Join Date: Nov 2008
Posts: 14
Like I said before I'm not a computer guy, I'm an admin guy so if I say something wrong please forgive my ignorance. When I run the script it enters ^priv and carriage returns which brings up the prompt (Select HOSPITAL LOCATION NAME:) at this prompt the script stops. I want it to enter the fistname of the clinic listed in Clinics.txt. After a clinic name is entered that genrates a prompt to Select PRIVILEGED USER:at this prompt I want to list a name in staff.txt when no new name is entered at the prompt just a carrige return the prompt returns to (Select HOSPITAL LOCATION NAME:) the next clinic name should be entered then that generates the Select PRIVILEGED USER: prompt. The error it does produce logs me out of my session and tells me to check line 35.
nameFile = fso.OpenTextFile("H:\\Application Data\\Van Dyke Technologies\\CRT\\Config\\Sessions\\Staff.txt", ForReading);

Version 4.1.6 (build 251) - Official Release - May 25, 2004
Reply With Quote
  #10  
Old 06-09-2009, 01:50 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 971
What is the exact text of the error message you see?

Can you post a screen-shot of the error message?

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #11  
Old 06-10-2009, 06:45 AM
sfchtm sfchtm is offline
Registered User
 
Join Date: Nov 2008
Posts: 14
I have attached a clip of the error window.
Attached Images
File Type: bmp Error.bmp (219.3 KB, 220 views)
Reply With Quote
  #12  
Old 06-10-2009, 10:02 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 971
Thanks for posting the screen-shot of the error message.

This error message means that your script tried to do something that requires an active connection (anything with crt.Screen.Send, or crt.Screen.WaitForString).

I'm not sure line 35 matches up with the code you have posted, but there are other problems with the code you have written:
  • You are using a variable named "str", which doesn't seem to be used anywhere else except in the following case (which occurs twice in your script):
    str += "\015";
    crt.Screen.Send( str );
    The two lines above do nothing but simulate pressing the Enter key -- nothing else is sent to the remote system because the variable str isn't used anywhere else (it isn't even declared anywhere).

    It could be that you really meant to use strCurrentSchedule instead of str in the first instance, and strCurrentName instead of str in the second instance. For example, the first instance where two lines currently use str could be replaced with one line:
    crt.Screen.Send( strCurrentSchedule + "\015" );
    And the second instand where two lines of code currently use str could be replaced with another single line of code:
    crt.Screen.Send( strCurrentName + "\015" );
  • Also, the braces in your code just aren't placed where they need to be. There should only be a total of 2 opening curly braces (placed on the line directly below each while statement) and 2 closing curly braces (placed at the end of each while loop -- meaning, after the last statement you need to perform as part of each while loop.

  • The crt.Screen.Synchronous = true; statement in your current code comes too late. It should come at the beginning of your script, or at least before you make any calls to crt.Screen.Send() or crt.Screen.WaitForString().

  • After you close the nameFile, it seems that your current code makes the mistake of waiting for "Select HOSPITAL LOCATION NAME:" without first "pressing" the Enter key (an important step in the process, as you described in your explanation of how you do this manually). After your nameFile.Close(); line of code, you should insert a crt.Screen.Send("\015"); line of code (above the crt.Screen.WaitForString("Select HOSPITAL LOCATION NAME:") line of code.

  • Also, your current script is missing a ";" character at the end of your crt.Screen.WaitForString("Select HOSPITAL LOCATION NAME:") line of code (in both places where this line occurs within your script).

After you address the bullet points I have made above (you'll need to revise your script code), you can try running your script code again and let us know how it turns out. If it still doesn't work after making the revisions to your script code, don't forget to provide us with an updated copy of your script code, along with any and all error messages you are seeing, as well as a detailed explanation of the behavior you are seeing -- all of this information is crucial to making progress towards a solution.

Also, if you're new to scripting (or coding in general), you might find the VBScript language a little easier to understand. In addition, if you upgrade to the current version of SecureCRT (6.2.1), you'll have access to a script recorder that you can use to "record" the steps you take when doing this process manually. Perhaps a script of you going through the process manually for one hospital location, followed by entering one privileged user, might provide a good basis for moving forward with automating it further with the use of the two files.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #13  
Old 06-11-2009, 10:13 AM
sfchtm sfchtm is offline
Registered User
 
Join Date: Nov 2008
Posts: 14
Without any instructional comments just the code. I believe I have addressed all your comments. It still stops at Select HOSPITAL LOCATION NAME:. It does not read the names of the clinics from the text file.


# $language = "JScript"
# $interface = "1.0"

function main()
{
crt.Screen.Send("^priv\r")

var fso, scheduleFile, nameFile;
var ForReading = 1, ForWriting = 2;
fso = new ActiveXObject("Scripting.FileSystemObject");

crt.Screen.Synchronous = true;

scheduleFile = fso.OpenTextFile("C:\\Application Data\\Van Dyke Technologies\\CRT\\Config\\Sessions\\Clinics.txt", ForReading);

while ( scheduleFile.AtEndOfStream != true )
{
strCurrentSchedule = scheduleFile.Readline();

crt.Screen.WaitForString("Select HOSPITAL LOCATION NAME:");

nameFile = fso.OpenTextFile("C:\\Application Data\\Van Dyke Technologies\\CRT\\Config\\Sessions\\Staff.txt", ForReading);

while ( nameFile.AtEndOfStream != true )
{
strCurrentName = nameFile.Readline();

crt.Screen.WaitForString( "Select PRIVILEGED USER:" );

nameFile.Close( );

crt.Screen.Send( strCurrentSchedule + "\015" );

crt.Screen.WaitForString("Select HOSPITAL LOCATION NAME:");

}
}
}

Last edited by sfchtm; 06-11-2009 at 10:24 AM.
Reply With Quote
  #14  
Old 06-11-2009, 11:44 AM
WesR WesR is offline
Registered User
 
Join Date: Mar 2005
Location: USA
Posts: 132
I don't know Jscript, but something you could try to see if it is reading the file is to put:

msgbox strCurrentSchedule

After your:

strCurrentSchedule = scheduleFile.Readline();

Entry. Another simular msgbox to show you the strCurrentName after the Readline for that variable.

Did you mean to have 2 wait for "Select HOSPITAL LOCATION NAME:" commands? I don't know your application, but I would have expected one of these to be waiting for a different prompt.

Wes
Reply With Quote
  #15  
Old 06-11-2009, 11:51 AM
sfchtm sfchtm is offline
Registered User
 
Join Date: Nov 2008
Posts: 14
Not sure if the second wait for "Select HOSPITAL LOCATION NAME:" is needed or not. It may be completely unnecessary but I can't get that far before script stops.
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 06:03 PM.