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 03-27-2006, 11:40 AM
corp-mule corp-mule is offline
Registered User
 
Join Date: Mar 2006
Posts: 21
clear screen and buffer



I want to ...

- Clear the screen
- Clear the buffer
- Run commands
- Copy the screen to the clipboard

Then I would paste the clipboard into a text file.

I haven't found a way to 'clear the buffer'. Can someone help me with that part?

This is what I have so far

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

sub main
' object.clear
crt.buffer.clear
crt.screen.clear
crt.screen.send vbCR
crt.screen.send "sh clock" & vbCR
crt.screen.send vbCR
crt.screen.send "term len 0" & vbCR
crt.screen.send "sh run" & vbCR
crt.screen.send vbCR
crt.screen.send "sh clock" & vbCR
crt.screen.send vbCR
end sub

Thanks,
corp-mule

Reply With Quote
  #2  
Old 03-27-2006, 01:07 PM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hi Corp-mule,

There is a method that can be used to clear the scrollback buffer.

The object is called CRT.Screen.SendSpecial.

With this object you can actually perform your first 2 objectives at one time.

To clear the screen and buffer, the syntax would be:

CRT.Screen.SendSpecial "MENU_CLEAR_SCREEN_AND_SCROLLBACK

To clear just the scrollback buffer:

CRT.Screen.SendSpecial "MENU_CLEAR_SCROLLBACK"

Was this the information that you needed?
__________________
Thanks,

Teresa

Teresa Nygren
Reply With Quote
  #3  
Old 03-27-2006, 01:44 PM
corp-mule corp-mule is offline
Registered User
 
Join Date: Mar 2006
Posts: 21

That was a big help tnygren!

I couldn't get the command that did both on one line to work, so I created two lines, and added a couple more.

The two lines at the end don't seem to be working ... see below.

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

sub main
' CRT.Screen.SendSpecial "MENU_CLEAR_SCREEN_AND_SCROLLBACK"
CRT.Screen.SendSpecial "MENU_CLEAR_SCREEN"
CRT.Screen.SendSpecial "MENU_CLEAR_SCROLLBACK"
crt.screen.send vbCR
crt.screen.send "sh clock" & vbCR
crt.screen.send vbCR
crt.screen.send "term len 0" & vbCR
crt.screen.send "sh run" & vbCR
crt.screen.send vbCR
crt.screen.send "sh clock" & vbCR
crt.screen.send vbCR
CRT.Screen.SendSpecial "MENU_SELECT_ALL"
CRT.Screen.SendSpecial "MENU_COPY"
end sub


This works up to a point. It doesn't appear to be copying the text that's selected (at the end of the script).

Out of curiosity -- (don't know if I'll do this or not ) -- I understand scripting can be used to create a text file too. Could the output generated above be placed in a text file?

Thanks,
corp-mule



Quote:
Originally Posted by tnygren
Hi Corp-mule,

There is a method that can be used to clear the scrollback buffer.

The object is called CRT.Screen.SendSpecial.

With this object you can actually perform your first 2 objectives at one time.

To clear the screen and buffer, the syntax would be:

CRT.Screen.SendSpecial "MENU_CLEAR_SCREEN_AND_SCROLLBACK

To clear just the scrollback buffer:

CRT.Screen.SendSpecial "MENU_CLEAR_SCROLLBACK"

Was this the information that you needed?
Reply With Quote
  #4  
Old 03-27-2006, 02:12 PM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hi Corp-mule,

As for the 'MENU_SELECT_ALL' and 'MENU_COPY' not copying the text, you may need to sleep the script for a bit to allow all the text to be selected before the copy command is issued.

As fast as scripts can issue commands, nothing may have been selected yet for the copy command to actually copy.

'CRT.Sleep <milliseconds>' can be used to pause the script long enough to allow the select all to actually select the text.

Does sleeping for a bit help the data to be captured?

As for the text file, this can be done by turning logging on before the data you would like to capture and then off afterwards.

The object is 'CRT.Session.Log(start[,append,[raw]])'. This will toggle logging on and off for that connection.

Was this what was needed for the text file or was there something more specific that you were looking for outside of logging the session?
__________________
Thanks,

Teresa

Teresa Nygren
Reply With Quote
  #5  
Old 03-27-2006, 02:46 PM
corp-mule corp-mule is offline
Registered User
 
Join Date: Mar 2006
Posts: 21
I tried the 'sleep' thing for 1000 milliseconds.

CRT.Sleep 1000

But that didn't seem to work. Before and after this change, it copies about 43 lines of nothing. in other words, when I paste into a text file, it's about 43 blank lines.
Reply With Quote
  #6  
Old 03-27-2006, 03:24 PM
corp-mule corp-mule is offline
Registered User
 
Join Date: Mar 2006
Posts: 21


I kept increasing the 'sleep' time ... up to 20000. This resulted in the display being slowed down, but still not capturing all the data.

It appears as though the copy function is happening as the data is being displayed, rather than after it's all finished being displayed.

So I guess I'd rather send it to a logfile, but that doesn't seem to be working either.

Here's what I've got so far....

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

sub main
' crt.screen.clear
' CRT.Screen.SendSpecial "MENU_CLEAR_SCREEN_AND_SCROLLBACK"
' CRT.Session.Log(start[,append,[raw]])
logfile = "I:\files\logs\scrt\test.txt"
crt.Session.LogFileName = "test.txt"
CRT.Session.Log (true)
CRT.Screen.SendSpecial "MENU_CLEAR_SCREEN"
CRT.Screen.SendSpecial "MENU_CLEAR_SCROLLBACK"
CRT.Sleep 1000
crt.screen.send vbCR
crt.screen.send "sh clock" & vbCR
crt.screen.send vbCR
crt.screen.send "term len 0" & vbCR
crt.screen.send "sh run" & vbCR
crt.screen.send vbCR
crt.screen.send "sh clock" & vbCR
crt.screen.send vbCR
CRT.Sleep 20000
CRT.Screen.SendSpecial "MENU_SELECT_ALL"
CRT.Screen.SendSpecial "MENU_COPY"
CRT.Session.Log (false)
end sub


Thanks

Reply With Quote
  #7  
Old 03-27-2006, 03:24 PM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hi Corp-mule,

If the copy is running early, a delay may need to be placed before the copy command.

I was successful running that script with a 2000 delay before the select all command.

Do the commands take a bit of time to run?

Is anything being placed in the log file?
__________________
Thanks,

Teresa

Teresa Nygren

Last edited by tnygren; 03-27-2006 at 03:28 PM.
Reply With Quote
  #8  
Old 03-27-2006, 03:31 PM
corp-mule corp-mule is offline
Registered User
 
Join Date: Mar 2006
Posts: 21


You've probably seen my earlier post by now (about the sleep timer being 20000). I have a lot of data being output, over 2000 lines of text.

My buffer is set for the max (32000).

Are my loging commands correct? That's not working.

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

sub main
' crt.screen.clear
' CRT.Screen.SendSpecial "MENU_CLEAR_SCREEN_AND_SCROLLBACK"
' CRT.Session.Log(start[,append,[raw]])
logfile = "I:\files\logs\scrt\test.txt"
crt.Session.LogFileName = "test.txt"
CRT.Session.Log (true)
CRT.Screen.SendSpecial "MENU_CLEAR_SCREEN"
CRT.Screen.SendSpecial "MENU_CLEAR_SCROLLBACK"
'CRT.Sleep 1000
crt.screen.send vbCR
crt.screen.send "sh clock" & vbCR
crt.screen.send vbCR
crt.screen.send "term len 0" & vbCR
crt.screen.send "sh run" & vbCR
crt.screen.send vbCR
crt.screen.send "sh clock" & vbCR
crt.screen.send vbCR
'CRT.Sleep 20000
CRT.Screen.SendSpecial "MENU_SELECT_ALL"
CRT.Screen.SendSpecial "MENU_COPY"
CRT.Session.Log (false)
end sub



Reply With Quote
  #9  
Old 03-27-2006, 04:58 PM
jjh jjh is offline
VanDyke Customer Support
 
Join Date: Feb 2004
Posts: 819
Hello corp-mule.

It looks like you have some conflicting lines with regard to
the log file. You'll probably also have to uncomment the
line that sleeps.

Do you get better behavior if you change your script to look
like this?:

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

sub main
' crt.screen.clear
' CRT.Screen.SendSpecial "MENU_CLEAR_SCREEN_AND_SCROLLBACK"
' CRT.Session.Log(start[,append,[raw]])
logfile = "I:\files\logs\scrt\test.txt"
crt.Session.LogFileName = logfile
CRT.Session.Log (true)
CRT.Screen.SendSpecial "MENU_CLEAR_SCREEN"
CRT.Screen.SendSpecial "MENU_CLEAR_SCROLLBACK"
'CRT.Sleep 1000
crt.screen.send vbCR
crt.screen.send "sh clock" & vbCR
crt.screen.send vbCR
crt.screen.send "term len 0" & vbCR
crt.screen.send "sh run" & vbCR
crt.screen.send vbCR
crt.screen.send "sh clock" & vbCR
crt.screen.send vbCR
CRT.Sleep 20000
CRT.Screen.SendSpecial "MENU_SELECT_ALL"
CRT.Screen.SendSpecial "MENU_COPY"
CRT.Session.Log (false)
end sub
Reply With Quote
  #10  
Old 04-04-2006, 07:50 PM
lele's Avatar
lele lele is offline
Registered User
 
Join Date: Aug 2005
Posts: 4
Code:
# $language = "VBScript"
# $interface = "1.0"

sub main
' crt.screen.clear
' CRT.Screen.SendSpecial "MENU_CLEAR_SCREEN_AND_SCROLLBACK"
' CRT.Session.Log(start[,append,[raw]])
logfile = "I:\files\logs\scrt\test.txt"
crt.Session.LogFileName = logfile
CRT.Session.Log (true)
CRT.Screen.SendSpecial "MENU_CLEAR_SCREEN"
CRT.Screen.SendSpecial "MENU_CLEAR_SCROLLBACK"
'CRT.Sleep 1000
crt.screen.send vbCR
crt.screen.send "sh clock" & vbCR
crt.screen.send vbCR
crt.screen.send "term len 0" & vbCR
crt.screen.send "sh run" & vbCR
crt.screen.send vbCR
crt.screen.send "sh clock" & vbCR
crt.screen.send vbCR
CRT.Sleep 20000
CRT.Screen.SendSpecial "MENU_SELECT_ALL"
CRT.Screen.SendSpecial "MENU_COPY"
CRT.Session.Log (false)
end sub
[/QUOTE]

To tnygren, pls help me how this script auto repeat after 5' ( Mean : i want to this scrip always auto repeat load on CRT)
i can't write that code
Reply With Quote
  #11  
Old 04-05-2006, 09:34 AM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hi Lele,

I'm not certain that I completely understand what you would like the script to do.

Did you need it to run each time CRT starts?

Does it need to run 5 times and then stop?

If it is neither of these, could you tell me more about how the script needs to run?
__________________
Thanks,

Teresa

Teresa Nygren
Reply With Quote
  #12  
Old 04-05-2006, 07:47 PM
lele's Avatar
lele lele is offline
Registered User
 
Join Date: Aug 2005
Posts: 4
thanks for your care
i want :
- my script auto load when i star CRT
- after loading, it will auto repeat with period : once every five minute.
Can you understand ?
Reply With Quote
  #13  
Old 04-06-2006, 09:33 AM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hello Lele.

Thanks for the clarification.

To start the script each time that CRT connects to that server, just specify the script in the 'Logon script:' data field in the 'Logon Scripts' sub-category under 'Connection' in the 'Session Options' of CRT 5.x.

This will cause the script to run each time this session is started.

As for making it run continuously, this can be done by placing what needs to be repeated in a Do/Loop in the script.

For example:
Quote:
Do

CRT.sleep 1000

Msgbox "I'm just looping some text"

CRT.sleep 5000

Loop
Scripts that are set to loop and do not have anything that will break the Do/Loop, will have to be cancelled from the 'Script' menu to stop the script fro running.

To make the script wait for 5 minutes, this can be done with the wscript.sleep object that is in VBS script or with 'crt.sleep' with a 5 minute timeout (300,000 milliseconds).

Either will work but if other thing will be happening in the session, it may be better to use the object in VBScript so that CRT is not just waiting for the next script command.

Was this the information that you needed?
__________________
Thanks,

Teresa

Teresa Nygren

Last edited by tnygren; 04-06-2006 at 09:35 AM.
Reply With Quote
  #14  
Old 04-06-2006, 10:23 AM
dan.d.jones dan.d.jones is offline
Registered User
 
Join Date: Apr 2006
Posts: 11
Wait for prompt

I'd recommend adding a line to wait for the prompt after the last command:

crt.Screen.Send "sh clock" & vbCR
crt.Screen.Send vbCR
crt.Screen.WaitForString"HOSTNAME#"
crt.Screen.SendSpecial "MENU_SELECT_ALL"
crt.Screen.SendSpecial "MENU_COPY"


I'm assuming this is a Cisco router which has a prompt of "HOSTNAME#". Change as appropriate. (You can also add a timeout and trap that to check for errors on the WaitForString line.) This will wait until you get back to the prompt before it tries to copy and paste the data. If necessary, place a sleep command BETWEEN the two SendSpecial lines. In other words, send the command to select all, wait a few milliseconds, then send the command to copy.

crt.Screen.SendSpecial "MENU_SELECT_ALL"
crt.Sleep 100
crt.Screen.SendSpecial "MENU_COPY"

BTW, you could also accomplish this whole thing by turning on logging at the start of issuing the command and turning it back off after getting back to the router prompt.
Reply With Quote
  #15  
Old 04-06-2006, 09:16 PM
lele's Avatar
lele lele is offline
Registered User
 
Join Date: Aug 2005
Posts: 4
Hello tnygren
Your guide is right with my ask, but i don't understand why my script doen't loop ?
Pls help me,
Do

CRT.sleep 1000

Msgbox "I'm just looping some text"

CRT.sleep 5000

Loop

what command i will exchange at (Msgbox "I'm just looping some text") to my script auto loop with period one every five minutes ?
Thanks for your help
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 10:17 AM.