Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1  
Old 10-20-2020, 12:30 PM
samky2005 samky2005 is offline
Registered User
 
Join Date: Feb 2010
Posts: 12
save in the text file

Hello

I was able to use ReadString() to capture the output of "show running-config" command and save it into the file using objFile.WriteLine.
However the very first line in the text file included the command.
Is there way not to include the command in the text file?

Code:
  Dim objTab, szCommand

  Set objTab = crt.GetScriptTab
 
  szCommand = "show cur"
  objTab.Screen.Send szCommand & chr(13)
  objTab.Screen.WaitForString vbCr 
  
  Dim strResult, objFile
  strResult = objTab.Screen.ReadString ("return",3)
  Set objFile = g_fso.OpenTextFile("c:\temp\config_sample.txt", ForWriting, True)
  objFile.WriteLine strResult
  objFile.Close

Thank you
Samky2005

Last edited by cboyack; 10-20-2020 at 12:50 PM. Reason: Please use [CODE] and [/CODE] tags to denote code strings
  #2  
Old 10-20-2020, 01:00 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
Quote:
Originally Posted by samky2005 View Post
...the very first line in the text file included the command. Is there way not to include the command in the text file?
This problem may have already been solved. Have you seen this example yet? More example scripts can be found in the Script Examples "sticky".

Regardless, to answer your question, you're doing this:
Code:
  szCommand = "show cur"
  objTab.Screen.Send szCommand & chr(13)
  objTab.Screen.WaitForString vbCr
If you don't want the command included in the captured output, then wait for it (the command text itself and the CR you're sending) to appear on the screen before you call ReadString(). For example...
Code:
  strCommand = "show cur"
  objTab.Screen.Send strCommand & vbcr
  ' Instead of just waiting for a CR, let's wait for the
  ' entire command to appear:
  objTab.Screen.WaitForString strCommand & vbcr
--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
  #3  
Old 10-20-2020, 01:32 PM
samky2005 samky2005 is offline
Registered User
 
Join Date: Feb 2010
Posts: 12
No. I couldn't find the post. Thank you for sharing.

And thank you very much for quick fix on my script. That met my expectation.

Thanks
Samky2005
  #4  
Old 10-22-2020, 03:41 AM
samky2005 samky2005 is offline
Registered User
 
Join Date: Feb 2010
Posts: 12
SSH vs Serial

I happened to find the script didn't work for Serial connection. It works for SSH session. I tried to find the solution but not yet solved.

Appreciated any insight.

Thanks
samky2005
  #5  
Old 10-22-2020, 09:23 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
Quote:
Originally Posted by samky2005 View Post
I happened to find the script didn't work for Serial connection. It works for SSH session. I tried to find the solution but not yet solved.

Appreciated any insight.
It might help to know more about what "didn't work" looks like.

Can you share more details about how the script failed for you? For example:
  1. Did you change only the protocol (connected to the exact same device, but with the Serial protocol), or did you also change the type of device to which you were connecting?
    • If you changed the type of device, what device is it?

  2. What output do you see in SecureCRT's terminal window?

  3. What error messages did the script report, if any?

  4. If the script didn't report any errors and seems to have been "hung", if you open the main Script pull-down menu in SecureCRT, is the Cancel menu item enabled?
    • If Cancel is enabled, what data is reported when you choose it?

  5. What other details can you share about what "didn't work" looks like?

.
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
  #6  
Old 10-22-2020, 11:55 AM
samky2005 samky2005 is offline
Registered User
 
Join Date: Feb 2010
Posts: 12
Hello Jake

Sorry for the ambiguity.

The issue was when the serial(COM1) protocol was used, the created file was empty.
The device wasn't changed.
The script ended without any error and also didn't hung.

I attached the zip file FYI.
I inserted 'MsgBox strResult' as for the troubleshooting. It returned empty with Serial but returned the result as I expect.

I'm using 8.0.0.

Thansk
Samky2005
Attached Files
File Type: zip writefile.zip (781 Bytes, 664 views)
Closed Thread

Tags
readstring , save to a file

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:59 AM.