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 04-23-2012, 11:12 AM
CKilinski CKilinski is offline
Registered User
 
Join Date: Apr 2012
Posts: 3
Use device hostname as variable

Hi, I've been making scripts to automate configuration backups from some switches and other devices, and want to simplify the process a bit. Instead of creating a separate .vbs for every device and changing the tftp filename in the command, I'd like to be able to grab the device name from the terminal output and use that as a variable when determining what filename to send back to the terminal.

The terminal output is pretty standard ("Switch1#" on every line)

Basically I want to do something like this (syntax not correct):
crt.Screen.Send "copy config tftp address 10.0.0.1 filename " & hostname & ".txt"

Does anyone know if this is possible, and if so, how I might go about doing this?

Thanks a lot

Christian
Reply With Quote
  #2  
Old 04-23-2012, 11:45 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,307
Hi Christian,

Thanks for the question. It is possible to concatenate variables into strings using the ampersand.

The syntax you posted appears to be correct and should send the following to the remote device:
copy config tftp address 10.0.0.1 filename <hostname>.txt
The <hostname> would be replaced with what you have defined the variable to be.

If the line of code is failing, would you post the error message?

Have you defined the "hostname" variable?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 04-23-2012, 12:11 PM
CKilinski CKilinski is offline
Registered User
 
Join Date: Apr 2012
Posts: 3
The question I have is how to actually make the variable - I'm not sure how exactly to capture the hostname from the terminal output and put it into a vbs variable. I found another thread on this subject and it suggested

crt.Screen.Send vbcr
crt.Screen.WaitForString vbcr

Dim hostname
hostname = replace(crt.Screen.ReadString("#"),vbCRLF,"")
hostname = replace(hostname," ","_")

crt.Screen.Send "copy config tftp address 10.0.0.1 filename " & hostname & "-new" & chr(13)

Which actually did work for a couple switches, but for others it does nothing at all. I'm not sure what the proper way to do things is

Thanks
Reply With Quote
  #4  
Old 04-23-2012, 01:59 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,307
Hi Christian,

Thanks for the update. What you are doing is a way to accomplish your goal. There are likely other ways as well.

When you say "but for others it does nothing at all", can you elaborate?

If you can cancel the script, what line is indicated in the dialog when doing so?

I would suggest adding a message box after you manipulate the hostname to see what was captured. For example:
PHP Code:
hostname replace(hostname," ","_")
crt.Dialog.MessageBox hostname 
Is the captured string what you expect?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #5  
Old 04-24-2012, 07:57 AM
CKilinski CKilinski is offline
Registered User
 
Join Date: Apr 2012
Posts: 3
I actually got it to work with the others, apparently it was more of a timing issue as some of the switches we use are not as responsive as others. Thanks for the help, I appreciate it.
Reply With Quote
  #6  
Old 04-24-2012, 08:42 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,307
Hi Christian,

Thanks for the update. I am glad to help and hear that your script is now working.
__________________
--Todd

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 05:43 PM.