Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #16  
Old 07-18-2014, 03:51 PM
hvh2000 hvh2000 is offline
Registered User
 
Join Date: Jul 2014
Posts: 4
Hi Todd! I am using the vbs version, and that did the trick! Thanks a lot!
Reply With Quote
  #17  
Old 07-18-2014, 04:09 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,307
You are welcome hvh2000. I am glad I could help.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #18  
Old 08-13-2014, 04:09 PM
hvh2000 hvh2000 is offline
Registered User
 
Join Date: Jul 2014
Posts: 4
host prompt changes

Hi Todd,
I ran into a bit of a problem with the vbscript version. I am issuing commands to a (cisco) device, and the script stops when I issue "config term", because the prompt changes from hostname# to hostname(config)#.

How do I modify the script to continue executing commands when the prompt changes from # to config)#?

Adding the current version I'm working with. I added cases for when I need to elevate privileges on a device to be able to work with it. Let me know if I need to clarify anything further.
Reply With Quote
  #19  
Old 08-13-2014, 05:07 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,307
Hi hvh2000,

There are many ways to accomplish your goal. I know that there is a thread that discusses this exact change. If I can find the thread, I will post it.

The line that needs to be modified in the original script would be 251. Rather than waiting for the prompt, you could wait for all possible prompts. If strPrompt is defined as hostname#, then you could create a new variable by replacing the # with (config)#. For example:
strConfigPrompt = Replace(strPrompt, "#", "(config)#")
The ReadString() call would have multiple strings. For example:
strResult = ReadString(strPrompt, strConfigPrompt)
Does this help?
__________________
--Todd

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

Last edited by rtb; 08-14-2014 at 09:28 AM.
Reply With Quote
  #20  
Old 08-14-2014, 09:18 AM
hvh2000 hvh2000 is offline
Registered User
 
Join Date: Jul 2014
Posts: 4
Thanks Todd!! That did the trick!
Reply With Quote
  #21  
Old 08-16-2014, 09:14 AM
aluminex aluminex is offline
Registered User
 
Join Date: Aug 2014
Posts: 3
Dynamic prompt

Todd,

I am trying to do the same thing, but the prompts are much more dynamic. I edited the script and added several prompts, but they literally change with every directory. Any idea how I could alter the script to provide support for dynamic prompts or perhaps trimming everything out except the #.

Thanks
Reply With Quote
  #22  
Old 08-18-2014, 10:55 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,307
Hi aluminex,

Thanks for the post. The goal is to use something generic enough to work with a wide range of possibilities, but unique enough to prevent false positives.

Is the # symbol unique enough that you the script won't find it in the output of a command that is run?

What types of devices are you connecting to when using the script?

Is it possible to change the shell prompt on the devices?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #23  
Old 08-19-2014, 06:56 AM
aluminex aluminex is offline
Registered User
 
Join Date: Aug 2014
Posts: 3
Quote:
Originally Posted by rtb View Post
Hi aluminex,

Thanks for the post. The goal is to use something generic enough to work with a wide range of possibilities, but unique enough to prevent false positives.

Is the # symbol unique enough that you the script won't find it in the output of a command that is run?

What types of devices are you connecting to when using the script?

Is it possible to change the shell prompt on the devices?
Todd,

Thanks for the reply. I am connecting to Fortigate firewalls (FortiOS), and Cisco routers. I think # would be unique enough... not certain though.
Reply With Quote
  #24  
Old 08-19-2014, 10:51 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,307
Hi aluminex,

Thanks for the update. You will have to run tests, but a simple way to test would be to comment out line 195, and add a line after it that sets strPrompt equal to what you want. For example:
strPrompt = "#"
Does this work for you?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #25  
Old 08-19-2014, 03:27 PM
aluminex aluminex is offline
Registered User
 
Join Date: Aug 2014
Posts: 3
Works great Todd! Thanks!
Reply With Quote
  #26  
Old 08-19-2014, 04:09 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,307
Hi aluminex,

Thanks for the update. I am glad to hear that the change is working.

Please remember, that this is a hardcoded string that is not terribly unique. If you get to a point where the script is not functioning as you expect, you may consider looking at the output to ensure that the "#" is not appearing before you expect it to appear (in the prompt).
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #27  
Old 09-11-2014, 04:23 PM
aaakaundal aaakaundal is offline
Registered User
 
Join Date: Sep 2014
Posts: 2
Hi Todd!!

I am trying to use the vbs version of the script but not able to login to devices. I am suspecting that this script is based on ssh login to devices but my devices are only enabled for telnet access only.

Is there any version that uses telnet protocol to login to devices instead of ssh.
Reply With Quote
  #28  
Old 09-11-2014, 05:02 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,307
Hi aaakaundal,

Thanks for the post.

Actually, if you look at the Connect() function in the VBScript version of the script, you will see on lines 429 to 437 that many different strings are handled. It is anticipated that Telnet connections should work as well.

If you find that there is a response from the remote that isn't handled, you can add the new response and a new case to handle the response.

Does this help?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #29  
Old 10-01-2014, 09:06 AM
aaakaundal aaakaundal is offline
Registered User
 
Join Date: Sep 2014
Posts: 2
Quote:
Originally Posted by rtb View Post
Hi aaakaundal,

Thanks for the post.

Actually, if you look at the Connect() function in the VBScript version of the script, you will see on lines 429 to 437 that many different strings are handled. It is anticipated that Telnet connections should work as well.

If you find that there is a response from the remote that isn't handled, you can add the new response and a new case to handle the response.

Does this help?
I modified below script portion from ssh to telnet and its working.


'
' If you want to authenticate with publickey authentication instead of
' password, in the assignment of strConnectString below, replace:
' " /AUTH password,keyboard-interactive /PASSWORD " & g_strPassword & _
' with:
' " /AUTH publickey /I ""full_path_to_private_key_file"" " & _
strConnectString = _
g_strFirewall & _
" /TELNET " & g_strHost & " 23"

' Call the Connect() function defined below in this script. It handles
' the connection process, returning success/fail.
If Not Connect(strConnectString) Then
strErrors = strErrors & vbcrlf & _
vbtab & "Failed to connect to " & g_strHost & _
": " & g_strError
Else
Reply With Quote
  #30  
Old 10-09-2014, 02:58 PM
kgaudineer kgaudineer is offline
Registered User
 
Join Date: Jan 2011
Posts: 15
Example script with Cisco device....

I am trying to use the example script (vbs) with a list of IP addreses for all of our Cisco switches. I have been able to get the script to work when using show commands. But now the script is failing when I try to use an tftp command after connecting to the Cisco switch.

What I am trying to do is tftp a copy of the startup config to a backup location.

The command is ....
copy startup-config tftp://tftp server address/folder/file name...

While the command can be entered entirely on a single line the response back from the switch will still require that the return key be pressed 2 more time before the command is executed so I choose to enter the entire command with 3 different line....

1. copy startup-config tftp:{enter}
2. [tftp servers ip address] {enter}
3. [name of file] which is a combo of IP address + strtup.cfg {enter}

The script runs all the way through entering the first command then hangs. I suspect that the response back from the switch is causing the script to hang because it is not he normal # prompt.

After the first command is entered the switch responds back with
address or name of remote host []? (this is where the tftp server IP goes)

but none of the other commands from the command file are entered. Is there a way to continue or should I look at creating a script from scratch ?
Reply With Quote
Reply

Tags
example script


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 07:55 PM.