Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-11-2013, 04:03 PM
chrismic1995 chrismic1995 is offline
Registered User
 
Join Date: Mar 2013
Posts: 10
Readstring and crt.Screen.Send backup to TFTP issue.

All, I am trying to automate the backup process of over a hundred layer 2 WWP/Ciena switches, however when I run the following script below, it paste in the "tput 10.70.28.199 " hits ENTER and then tries to run the rest of the script.

I am gathering the hostname of the switch and using it as the filename on the TFTP server.


____________________________________________________________________________________________________ ___________________________
Script

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

crt.Screen.Synchronous = True

' This automatically generated script may need to be
' edited in order to work correctly.

Sub Main
hostname = crt.Screen.ReadString(">")
crt.Screen.Send "tput 10.70.28.199 " & hostname & " /flash0/config/startup-config" & chr(13)
End Sub
____________________________________________________________________________________________________ ___________________________
Here is the results of running the script

LIBRARY-3920-CE> tput 10.70.28.199
ERROR: Incomplete tftp command
LIBRARY-3920-CE> LIBRARY-3920-CE /flash0/config/startup-config
SHELL PARSER FAILURE: 'LIBRARY-3920-CE' - invalid input
LIBRARY-3920-CE>

____________________________________________________________________________________________________ ___________________________
And here is me manually running the command

LIBRARY-3920-CE>
LIBRARY-3920-CE> tput 10.70.28.199 LIBRARY-3920-CE /flash0/config/startup-config
LIBRARY-3920-CE>


Any thoughts, I did notice that I have to hit ENTER to start the script, I believe that is what helps "match" the ReadString for the hostname...
  #2  
Old 03-11-2013, 05:01 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,448
Hello chrismic1995,

If you have to manually hit "ENTER" to kick things off, then the script is out of sync from the beginning.

It makes sense because the first item you are waiting for (in this case with ReadString()) is probably already displayed as part of the shell prompt.

How are you running the script?

If you put that "initial ENTER" into the script, what are the results?

Code:
Sub Main
    crt.Screen.Send vbcr
    hostname = crt.Screen.ReadString(">")
    crt.Screen.Send "tput 10.70.28.199 " & hostname & " /flash0/config/startup-config" & chr(13)
End Sub
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #3  
Old 03-11-2013, 05:24 PM
chrismic1995 chrismic1995 is offline
Registered User
 
Join Date: Mar 2013
Posts: 10
Thanks Brenda, however that still did not work? As expected you corrected the issue of having to hit the ENTER key but when the script runs it still outputs the command "tput 10.70.28.199" first, hits ENTER and then tries to run the rest of the command instead of running it all in one line?


Thanks,


CM
  #4  
Old 03-12-2013, 08:03 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,448
Hi chrismic1995,

Sorry, I left out an entire line of code when posting my response yesterday.

The problem is the "ENTER" you are sending to "kick off" the script is being captured as part of the ReadString().

So you want to send the CR via the script and also wait for it.

Code:
Sub Main
    crt.Screen.Send vbcr
    crt.Screen.WaitForString vbcr
    hostname = crt.Screen.ReadString(">")
    crt.Screen.Send "tput 10.70.28.199 " & hostname & " /flash0/config/startup-config" & chr(13)
End Sub
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #5  
Old 03-12-2013, 08:17 AM
chrismic1995 chrismic1995 is offline
Registered User
 
Join Date: Mar 2013
Posts: 10
Thanks Brenda, but it is still not working? Here is what the results were and what I have in my script:

LIBRARY-3920-CE>
LIBRARY-3920-CE> tput 10.70.28.199
ERROR: Incomplete tftp command
LIBRARY-3920-CE> LIBRARY-3920-CE /flash0/config/startup-config
SHELL PARSER FAILURE: 'LIBRARY-3920-CE' - invalid input
LIBRARY-3920-CE>






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

crt.Screen.Synchronous = True

' This automatically generated script may need to be
' edited in order to work correctly.

Sub Main
crt.Screen.Send vbcr
crt.Screen.WaitForString vbcr
hostname = crt.Screen.ReadString(">")
crt.Screen.Send "tput 10.70.28.199 " & hostname & " /flash0/config/startup-config" & chr(13)
End Sub





Thanks,



CM
  #6  
Old 03-12-2013, 09:05 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,448
Hi CM,

What protocol are you using to connect?

The "CR" is still being included in what is being sent for some reason.

You will plainly see this if you change the "send" line to a message box instead.

For example:

Code:
MsgBox "<tput 10.70.28.199 " & hostname & " /flash0/config/startup-config>"
My suspicion is that you will see this displayed on two lines.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #7  
Old 03-12-2013, 09:11 AM
chrismic1995 chrismic1995 is offline
Registered User
 
Join Date: Mar 2013
Posts: 10
I am using Telent, here is a screen shot of the MsgBox.


Thanks for the support...


CM
Attached Images
File Type: bmp ScreenOutPut.bmp (112.7 KB, 438 views)
  #8  
Old 03-12-2013, 09:33 AM
chrismic1995 chrismic1995 is offline
Registered User
 
Join Date: Mar 2013
Posts: 10
Also, I am using Version 7.0.2 (build 418) SecureCRT..


Thanks,


CM
  #9  
Old 03-12-2013, 10:02 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,448
Hi CM,

That may explain it.

If you enable Force character at a time mode in the Connection / Telnet category of SecureCRT's Session Options, what are the results?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #10  
Old 03-12-2013, 10:23 AM
chrismic1995 chrismic1995 is offline
Registered User
 
Join Date: Mar 2013
Posts: 10
I changed that for my default session option, closed out SecureCRT and re-opened and tried it again but still no go? Please see the attachment as an example.



Thanks,


CM
Attached Images
File Type: jpg FCAATM.jpg (110.4 KB, 442 views)
  #11  
Old 03-12-2013, 11:05 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,448
Hi CM,

I'm a bit confused.

So you are making an ad hoc connection (via Quick Connect), not using a saved session, correct?

Still, there is a line return being included (before hostname) in the send command.

Would you use the attached example script to message box what you are capturing with ReadString so we can see what non-printing characters or escape sequences are included?
Attached Files
File Type: txt RevealNonPrintingCharacters.vbs.txt (3.0 KB, 430 views)
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #12  
Old 03-12-2013, 11:19 AM
chrismic1995 chrismic1995 is offline
Registered User
 
Join Date: Mar 2013
Posts: 10
Do I need to edit your script and place my Sub Main in place of the crt.Screen.Send portion?

Sub Main()
strPrompt = "]-->"
crt.Screen.Synchronous = True
crt.Screen.Send "ls --color *.sh *.gz"
strReceivedData = crt.Screen.ReadString(strPrompt)
crt.Dialog.MessageBox RevealNonPrintingCharacters(strReceivedData)
End Sub


_____________________________________________________________

I am making a quick connection and yes a RETURN is being inputted before the "hostname".

If I remove the variable and place a static name everything works just fine, it places it all on one line.



Thanks,


CM
  #13  
Old 03-12-2013, 11:48 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,448
Hi CM,

Yes, pretty much. This example script is intended to see what is going on with your code.

Alter it (the RevealNonPrintingCharacters example script) as shown below:

Code:
Sub Main()
    crt.Screen.Synchronous = True
    crt.Screen.Send vbcr
    crt.Screen.WaitForString vbcr
    strReceivedData = crt.Screen.ReadString(">")
    crt.Dialog.MessageBox RevealNonPrintingCharacters(strReceivedData)
End Sub
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
  #14  
Old 03-12-2013, 11:58 AM
chrismic1995 chrismic1995 is offline
Registered User
 
Join Date: Mar 2013
Posts: 10
The attached has the output from the test script..


Thank you...


CM
Attached Images
File Type: jpg RNP-Output.jpg (9.2 KB, 446 views)
  #15  
Old 03-12-2013, 12:13 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,448
Hi CM,

Sorry, bear with me a moment while I adjust my dunce cap.

In your original script, change the WaitForString to vbcrlf, what are the results?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Closed Thread

Tags
backup , crt.screen.send , hostname , readstring , tftp


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 04:57 PM.