Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 03-22-2018, 11:13 AM
bmcken32 bmcken32 is offline
Registered User
 
Join Date: Mar 2018
Posts: 6
Sending config w/ questions

Hello,
I need some help with trying to figure out how to send approx. 80 lines of config that always stays the same with the exception of needing to ask approx. 8-10 questions along the way.

I configure telecom equipment, almost all the configs are the same with the exception of 8 lines where I need to change things like vlan id, customer name, interface description and name and so on.

I was able to create a script that asks the questions...but I have no idea how to get the answers inserted into the running script along the way.

Any help is greatly appreciated.


A short example would be:

crt.Screen.Send "delete system services dhcp" & chr(13)
crt.Screen.WaitForString "# "
crt.Screen.Send "delete chassis auto-image-upgrade" & chr(13) crt.Screen.WaitForString "# "
crt.Screen.Send "delete interfaces " & chr(13)
crt.Screen.Send "set system host-name EV.EX-3300.KENTRM.ETHS-OF-12090.INET" & chr(13)


My issue is:
crt.Screen.Send "set system host-name EV.EX-3300.KENTRM.ETHS-OF-12090.INET" & chr(13)

set system hostname will always be there, it's the EV.EX-3300.KENTRM.ETHS-OF-12090.INET that changes to whatever the hostname is each time.

There are more lines that need to change of course but this kind of gives my dilemma.


I can use this code to ask the questions...
strhostname = crt.Dialog.Prompt(_
"Please enter Hostname:", _
"Hostname?", _
"")
If strhostname = "" Then Exit Sub

But I don't know how to get it to pop up and ask along the way through the script or how to get it to insert the answers after the questions are asked and continue running the script.

Thanks for any help.
Reply With Quote
  #2  
Old 03-22-2018, 11:33 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
Hi bmcken32,

It looks like you're most of the way there.

Using your example:

Code:
crt.Screen.Send "delete system services dhcp" & chr(13) 
 crt.Screen.WaitForString "# "
 crt.Screen.Send "delete chassis auto-image-upgrade" & chr(13) crt.Screen.WaitForString "# "
 crt.Screen.Send "delete interfaces " & chr(13)
 crt.Screen.Send "set system host-name EV.EX-3300.KENTRM.ETHS-OF-12090.INET" & chr(13)
You could do something like:
Code:
crt.Screen.Send "delete system services dhcp" & chr(13) 
crt.Screen.WaitForString "# "
crt.Screen.Send "delete chassis auto-image-upgrade" & chr(13) crt.Screen.WaitForString "# "
crt.Screen.Send "delete interfaces " & chr(13)

strhostname = crt.Dialog.Prompt("Please enter Hostname:", "Hostname?", "") 
If strhostname = "" Then Exit Sub

crt.Screen.Send "set system host-name " & strhostname & chr(13)
This assumes you would like to replace "EV.EX-3300.KENTRM.ETHS-OF-12090.INET" from your first example with the results of the question you asked.

We have put together a nice Scripting Essentials Guide that may help you get up and running.
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 03-22-2018, 11:40 AM
bmcken32 bmcken32 is offline
Registered User
 
Join Date: Mar 2018
Posts: 6
That's great!
One more quick question...

If:
Code:
crt.Screen.Send "set system host-name " & strhostname & chr(13)
Is used I need to include the " at the end of the hostname..
So would it be:
Code:
crt.Screen.Send "set system host-name " & strhostname" & chr(13)
Some of the questions asked are inside quotes.

Thank you!
Reply With Quote
  #4  
Old 03-22-2018, 11:54 AM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
bmcken32,

No, "'s are required when you are sending the actual text, in the case of strhostname you aren't sending the actual text "strhostname" you are sending the value that the variable contains.

In your case you are assigning the answer to your question to a variable named strhostname. You then send the literal text in between the "'s followed by the information contained in the variable followed by the equivalent of hitting enter. If you enclosed strhostname in "'s you would see something like the below appear on screen regardless of what you answered to the question.

Code:
set system host-name strhostname
Does this help?
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 03-22-2018, 02:49 PM
bmcken32 bmcken32 is offline
Registered User
 
Join Date: Mar 2018
Posts: 6
Eric,
You've been a tremendous help so far..
Now I'm stuck on the script breaking at lines where the " are required.

Example:

Code:
crt.Screen.Send "set system root-authentication encrypted-password "$1$hMK6jbOy$EnQY02.rWsDSVU1Ab4I2w0" "& chr(13)  
crt.Screen.WaitForString "# "



Ideas on this one?
I'm SO close!
Reply With Quote
  #6  
Old 03-22-2018, 03:05 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
bmcken32,

If the text you need to send to the remote device includes "'s there are some considerations to take into account. Usually anything between the " " gets sent but if there is a " in the middle the script thinks you only want to send the stuff between the first two "". To let the script know that you want to send the "'s to the remote system you need to double them up.

This would look like:

crt.Screen.Send "set system root-authentication encrypted-password ""$1$hMK6jbOy$EnQY02.rWsDSVU1Ab4I2w0"" " & chr(13)

I've color coded the "'s to help illustrate which ones the script will see as pairs. Everything between the green " will be sent to the remote with the red " being converted to single " when sent.

You previous example was being interpreted as:

crt.Screen.Send "set system root-authentication encrypted-password "$1$hMK6jbOy$EnQY02.rWsDSVU1Ab4I2w0" "& chr(13)

I hope this helps clarify the problem you're running into.

Also, I assume these are dummy value's you've provided, I'm a little concerned about you having provided both hostnames and passwords in a public forum.
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #7  
Old 03-22-2018, 03:22 PM
bmcken32 bmcken32 is offline
Registered User
 
Join Date: Mar 2018
Posts: 6
Me again.

Yes those are random characters similar to what gets sent.

I DID find the double quote fix right after I posted in the guide you linked to, sorry for pre-maturely posting that question.

My issue now is that the Input request where it asks for the hostname works but it doesn't present the name I type in.

Or any place that it presents the text input, it won't type out the input.
All I get is:

Code:
root# set system host-name strhostname
Instead of
root# set system host-name ACTUALHOSTNAME

The script doesn't error out, it just doesn't present the input it asked for right before the line that needs it.

Make sense?
Reply With Quote
  #8  
Old 03-22-2018, 03:31 PM
ekoranyi ekoranyi is offline
VanDyke Technical Support
 
Join Date: Jan 2017
Posts: 654
bmcken32,

It sounds like you may have inadvertently enclosed the variable name in "'s.

If you want the contents of that variable to be sent it cannot be enclosed in quotes.

Code:
crt.Screen.Send "set system host-name " & strhostname & chr(13)
The code above should produce:
set system host-name ACTUALHOSTNAME
If you've done something like:

Code:
crt.Screen.Send "set system host-name " & "strhostname" & chr(13)
You would expect to see:
set system host-name strhostname
__________________
Thanks,
--Eric

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #9  
Old 03-27-2018, 02:15 PM
bmcken32 bmcken32 is offline
Registered User
 
Join Date: Mar 2018
Posts: 6
Well so far with all your help I've cleared all but one hurdle.

I'm stuck at the lines of config that need 2 input boxes.

The config doesn't reconize the first input box and only adds the & str... and doesn't add the rest of the line and skips to the next line of config.

Code:
    crt.Screen.Send "set interfaces ge- & strCustInterf mtu 9216" & chr(13) 
	crt.Screen.Waitforstring "# "
    crt.Screen.Send "set interfaces ge-& strCustInterf unit 0 description ""Link to & strCID"" " & chr(13)  
	crt.Screen.Waitforstring "# "
    crt.Screen.Send "set interfaces ge-& strCustInterf unit 0 family ethernet-switching port-mode access" & chr(13)  
	crt.Screen.Waitforstring "# "
    crt.Screen.Send "set interfaces ge-& strCustInterf unit 0 family ethernet-switching vlan member & strCID" & chr(13)  
	crt.Screen.Waitforstring "# "
    crt.Screen.Send "set interfaces ge-& strNetInterf mtu 9216" & chr(13)  
	crt.Screen.Waitforstring "# "
    crt.Screen.Send "set interfaces ge-& strNetInterf ether-options link-mode full-duplex" & chr(13)  
	crt.Screen.Waitforstring "# "
    crt.Screen.Send "set interfaces ge-& strNetInterf ether-options speed 100m" & chr(13)  
	crt.Screen.Waitforstring "# "
    crt.Screen.Send "set interfaces ge-& strNetInterf ether-options no-auto-negotiation" & chr(13)  
	crt.Screen.Waitforstring "# "
    crt.Screen.Send "set interfaces ge-& strNetInterf unit 0 description ""To & strNetIntdesc"" " & chr(13)  
	crt.Screen.Waitforstring "# "
    crt.Screen.Send "set interfaces ge-& strNetInterf unit 0 family ethernet-switching port-mode trunk" & chr(13)  
	crt.Screen.Waitforstring "# "
    crt.Screen.Send "set interfaces ge-& strNetInterf unit 0 family ethernet-switching vlan members Management" & chr(13)  
	crt.Screen.Waitforstring "# "
    crt.Screen.Send "set interfaces ge-& strNetInterf unit 0 family ethernet-switching vlan members & strCID" & chr(13)  
	crt.Screen.Waitforstring "# "
Sorry to be a pain...but all your help is greatly appreciated.
Reply With Quote
  #10  
Old 03-27-2018, 02:26 PM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,020
Hi bmcken32,

Maybe it was just *munged* when you copied/pasted, but aren't strCustInterf and strNetInterf variables?

If so, your quotes are still off. I will show one line below as I think it should be. You should be able to apply the same pattern to the rest (I really don't know if the asterisks and underlines are meant to be literal strings or not):
Code:
    crt.Screen.Send "set interfaces ge- *_" & strCustInterf & "_* mtu 9216" & chr(13)
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #11  
Old 03-28-2018, 08:00 AM
bmcken32 bmcken32 is offline
Registered User
 
Join Date: Mar 2018
Posts: 6
Quote:
Originally Posted by bgagnon View Post
If so, your quotes are still off. I will show one line below as I think it should be. You should be able to apply the same pattern to the rest (I really don't know if the asterisks and underlines are meant to be literal strings or not):
Code:
    crt.Screen.Send "set interfaces ge- *_" & strCustInterf & "_* mtu 9216" & chr(13)
Brenda,
Thanks for the help, I found out that the *_ is not needed and everything works great now!
Thank you so much, all you guys ROCK!
Reply With Quote
  #12  
Old 03-28-2018, 10:18 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,020
Hi bmcken32,

Thanks for posting the update and the positive feedback!
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
Reply


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 01:03 AM.