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 01-10-2012, 05:59 AM
jeraxx jeraxx is offline
Registered User
 
Join Date: Jan 2012
Posts: 8
Problem using readString()

Hi all,

First of all happy new year 2012!

I'm trying to read a simply date shell response but I can't. I was reading another threads related with this, also I was reading scripting pdf but with unsuccesful results.

Code:
fecha = "date ""+%Y%m%d%H%M%S"""
crt.Screen.Synchronous = True

crt.screen.send fecha & vbcr
strResult = crt.Screen.ReadString (vbcr) & vbcr

crt.screen.send strResult & vbcr
Shell responses me:
Code:
Last login: Tue Jan 10 12:56:18 2012 from 10.237.3.75
date "+%Y%m%d%H%M%S"
Last login: Tue Jan 10 12:56:18 2012 from 10.237.3.75

nmsguest@tb2i2kb:~> date "+%Y%m%d%H%M%S"
20120110135908
nmsguest@tb2i2kb:~> Last login: Tue Jan 10 12:56:18 2012 from 10.237.3.75
-bash: Last: command not found
nmsguest@tb2i2kb:~> 
nmsguest@tb2i2kb:~>
I can't store 20120110135908 into a variable.
Could someone help me please?
Thanks in advance.
Cheers
Reply With Quote
  #2  
Old 01-10-2012, 07:34 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi jeraxx,

Thanks for the question. I have included code that may help you accomplish your goal. The example includes comments to explain what the code is doing, and information on using MsgBox to help troubleshoot the code.
Code:
fecha = "date ""+%Y%m%d%H%M%S"""
crt.Screen.Synchronous = True

crt.Screen.Send fecha & vbcr
' Wait for command to be echoed back from remote.  This will prevent
' ReadString() from capturing the command that was sent.
crt.Screen.WaitForString vbcr
' Read from the prompt to the command.  This should capture the required data.
' By including the prompt in the command, the prompt will not be captured.
strResult = crt.Screen.ReadString("nmsguest@tb2i2kb:~>")
' You may want to see what was captured prior to sending it to ensure that it is
' the correct data.  If the variable contains more information that you need,
' you can use VBScript functions to remove the unwanted information.
' MsgBox strResult
crt.Screen.Send strResult & vbcr
Does this help resolve the issue?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 01-10-2012, 07:38 AM
jeraxx jeraxx is offline
Registered User
 
Join Date: Jan 2012
Posts: 8
Hi friend,

I tried to use your code but I obtain this:

Code:
Last login: Tue Jan 10 15:21:08 2012 from 10.237.3.75
date "+%Y%m%d%H%M%S"
nmsguest@tb2i2kb:~> date "+%Y%m%d%H%M%S"
20120110153906
nmsguest@tb2i2kb:~> 
nmsguest@tb2i2kb:~> 
nmsguest@tb2i2kb:~> date "+%Y%m%d%H%M%S"
20120110153906
nmsguest@tb2i2kb:~> 
nmsguest@tb2i2kb:~> 
nmsguest@tb2i2kb:~> 
nmsguest@tb2i2kb:~>
I think it's only reading 2nd line (date "+%Y%m%d%H%M%S")
Thanks for your assistance

Last edited by jeraxx; 01-10-2012 at 07:49 AM.
Reply With Quote
  #4  
Old 01-10-2012, 08:00 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi jeraxx,

Thanks for the update. What do you see if you message box the results of reading the output?

You would need to uncomment the MsgBox strResult line of code. For example:
Code:
fecha = "date ""+%Y%m%d%H%M%S"""
crt.Screen.Synchronous = True

crt.Screen.Send fecha & vbcr
' Wait for command to be echoed back from remote.  This will prevent
' ReadString() from capturing the command that was sent.
crt.Screen.WaitForString vbcr
' Read from the prompt to the command.  This should capture the required data.
' By including the prompt in the command, the prompt will not be captured.
strResult = crt.Screen.ReadString("[nmsguest@tb2i2kb:~>")
' You may want to see what was captured prior to sending it to ensure that it is
' the correct data.  If the variable contains more information that you need,
' you can use VBScript functions to remove the unwanted information.
MsgBox strResult
crt.Screen.Send strResult & vbcr
__________________
--Todd

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

Last edited by rtb; 01-10-2012 at 08:26 AM.
Reply With Quote
  #5  
Old 01-10-2012, 08:23 AM
jeraxx jeraxx is offline
Registered User
 
Join Date: Jan 2012
Posts: 8
Hi again Rtb,

I can see complete command In the message box : date "+%Y%m%d%H%M%S", not the timestamp I'm looking for.

What could be happening?

Cheers
Reply With Quote
  #6  
Old 01-10-2012, 08:29 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi jeraxx,

Would you post the code you are using now?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #7  
Old 01-10-2012, 08:40 AM
jeraxx jeraxx is offline
Registered User
 
Join Date: Jan 2012
Posts: 8
Hi Rbt,

here you are:

Code:
fecha = "date ""+%Y%m%d%H%M%S"""
crt.Screen.Synchronous = True

crt.screen.send fecha & vbcr
crt.Screen.waitforstring vbcr
strResult = crt.Screen.ReadString ("nmsguest@tb2i2kb:~>")
MsgBox strResult
crt.screen.send strResult & vbcr
Reply With Quote
  #8  
Old 01-10-2012, 08:59 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi jeraxx,

Thanks for the information. Would you send two raw logs to support@vandyke.com with a subject of Attn: Todd - Forum thread 10239?

Here is how you can create a raw log:
  1. Before connecting with the session, select Raw Log Session from SecureCRT's File menu.
  2. In the Select Log File dialog, choose a folder and filename in which you would like the log text to be stored and click the Save button. At this point, if you open the File menu, you will notice that Raw Log Session now has a check-mark next to it; this indicates that raw logging is activated.
  3. Now connect to the remote machine and perform the actions which cause the reported problem to occur.
  4. Disconnect the session and select Raw Log Session from the File menu to turn off the raw log feature.
  5. Browse to the location of the raw log file and attach it to your message.
I would like to get a raw log capturing you manually issuing the command, and one where you run the script.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #9  
Old 01-10-2012, 09:21 AM
jeraxx jeraxx is offline
Registered User
 
Join Date: Jan 2012
Posts: 8
sent!

but I think both logs do not clarify too much ...

Thank you Rbt
Reply With Quote
  #10  
Old 01-10-2012, 10:14 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi jeraxx,

Thanks for the raw logs. It turns out that I missed a simple problem in the script initially, and when I ran my tests on the code I posted, I didn't encounter the timing issue that you are encountering.

Here is a new example that should help resolve the issue:
Code:
fecha = "date ""+%Y%m%d%H%M%S"""
crt.Screen.Synchronous = True

' Ensure that the remote is ready to receive a command.  Timeout after 1 second
' if the prompt is not found because we can be fairly certain that the prompt
' has already been received.
crt.Screen.WaitForString ">", 1
crt.Screen.Send fecha & vbcr
' Wait for command to be echoed back from remote.  This will prevent
' ReadString() from capturing the command that was sent.
crt.Screen.WaitForString vbcr
' Read from the carriage return/linefeed after the command to the carriage
' return we sent when issuing the command.  This should capture the required
' data. It should also avoid having to trim the data we read.
strResult = crt.Screen.ReadString(vbcrlf)
' You may want to see what was captured prior to sending it to ensure that it is
' the correct data.  If the variable contains more information that you need,
' you can use VBScript functions to remove the unwanted information.
' MsgBox strResult
crt.Screen.Send strResult & vbcr
Does this help to resolve the issue?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #11  
Old 01-11-2012, 12:34 AM
jeraxx jeraxx is offline
Registered User
 
Join Date: Jan 2012
Posts: 8
cool !!
Now it works!
Thank you very much Todd!!


Cheers
Juanjo
Reply With Quote
  #12  
Old 01-11-2012, 07:38 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
You are welcome Juanjo. I am glad to hear of your success.

Please post any other scripting questions you might have.
__________________
--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 01:40 PM.