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, 11:30 AM
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 11:50 AM. Reason: Please use [CODE] and [/CODE] tags to denote code strings
  #2  
Old 10-20-2020, 12: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, 12: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, 02: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, 08: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, 10: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, 820 views)
  #7  
Old 10-22-2020, 12:18 PM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
Samky2005,

For further troubleshooting efforts, we'll need to have more information provided.

Because these next steps will involve sensitive information that should not be posted to the public forums, please send email to support@vandyke.com:
  • Subject: "ATTN: Forum thread 14320"
  • Also, Please attach a screen shot of the About SecureCRT... window.
  • Also, Please attach a raw log of the interaction you have with the device from start to finish when you connect with Serial to the device and run the exact same sequence of steps that the script does. To create a raw log:
    • Before connecting with the session, select "Raw Log Session" from SecureCRT's "File" menu.
    • In the "Select Log File" dialog, choose a folder and filename in which you would like the log text to be stored and press the "Save" button. At this point, if you open the "File" menu, you will notice that the "Raw Log Session" menu item now has a check-mark next to it; this indicates that raw logging is activated.
    • Now connect to the remote machine and run the same commands that the script runs.
    • Once all the output is on the screen, disconnect the session and select "Raw Log Session" from the "File" menu to turn off the raw logging feature.
    • Browse to the location of the raw log file and add the file as an attachment to the e-mail message you're sending in.
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
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 05:33 AM.