Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > General

Notices

Reply
 
Thread Tools Display Modes
  #1  
Old 04-11-2016, 09:36 AM
faiz_usmani faiz_usmani is offline
Registered User
 
Join Date: Apr 2016
Posts: 7
Post Script to login to multiple devices based on a pattern and run the same commands

Dear all,
I have very limited knowledge of coding however I have searched through a few forum results and I am using sCRT from past 2 months and would like to customize it as per my needs.
Is there a sample script you can provide which I use on the button which checks a pattern of the saved session hostname like "dccore" and logs in them and run a few commands on them like "show interface | i notconnect" , "show vlan brie" and "show version" and saves the output in a file for all of them or present them in the sCRT tabs?

Please be patient as my understanding is very limited as beginer in coding world.

Thanks,
Faiz
Reply With Quote
  #2  
Old 04-11-2016, 09:49 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi Faiz,

What version of SecureCRT are you using?

On what OS/platform?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #3  
Old 04-12-2016, 07:47 AM
Sascha Sascha is offline
Registered User
 
Join Date: Apr 2016
Posts: 7
This happens to me too.

I tried the recorder function and it works fine for the easy steps. (paste the line per line my commands)

so my last command is quite tricky.

I tried to save the startup-config from my device to an ftp server.

What I need is a short scriptline to insert the hostname in my command.

Command looks:

copy nvram startup-config tftp 62.xxx.xxx.xxx config/cmts/<hostname>-confg

I have 200 devices and in the past I entered my commands line per line manually. Since last week i use secureCRT and try to automate some worksteps.

Hope find someone with fun to help me. :-)

I use secureCRT 8 and MAC OS X el Capitan.
Reply With Quote
  #4  
Old 04-12-2016, 10:51 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi Sascha,

I am not sure it answers Faiz's inquiry, but for yours, you can use SessionConfiguration object.

See SecureCRT's Help file topic Scripting / Script Objects Reference / SessionConfiguration Object.

Any session INI option that is preceded by S (string), Z (multi-string) or D (DWORD) can be *set* (SetOption) or *returned* (GetOption) via this object, using those methods.

For example, in Python, you might have:

Code:
objTab = crt.GetScriptTab()
objConfig = objTab.Session.Config
strHostname = objConfig.GetOption("Hostname")

objTab.Screen.Send("copy nvram startup-config tftp 62.xxx.xxx.xxx config/cmts/" + strHostname + "-confg\r\n")
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #5  
Old 04-13-2016, 03:02 AM
faiz_usmani faiz_usmani is offline
Registered User
 
Join Date: Apr 2016
Posts: 7
Post Reply

Hi Brenda,

I am trying to post but reply is not appearing in the main console.

sCRT = Version 7.2.6 (x64 build 606) - Official Release - August 19, 2014
Windows = 8.1 64 bit

Regds
Faiz
Reply With Quote
  #6  
Old 04-13-2016, 09:53 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi Faiz,

Quote:
I am trying to post but reply is not appearing in the main console.
A certain number of posts are moderated for new forum members.


Quote:
Is there a sample script you can provide which I use on the button which checks a pattern of the saved session hostname like "dccore" and logs in them and run a few commands on them like "show interface | i notconnect" , "show vlan brie" and "show version" and saves the output in a file for all of them or present them in the sCRT tabs?
What do you mean "checks a pattern of ... the hostname"?

Is there going to be a "hard-coded list" to match against?

Or will it be more dynamic, such as "starts with dcc"?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #7  
Old 04-14-2016, 04:59 AM
faiz_usmani faiz_usmani is offline
Registered User
 
Join Date: Apr 2016
Posts: 7
Hi Brenda,

This is what I am looking to achieve.

Q: What do you mean "checks a pattern of ... the hostname"?
Ans: I have plenty saved sessions in the sCRT console, those I am talking about to be cross checked against the hostname pattern.


Q: Is there going to be a "hard-coded list" to match against?
Ans: All the sessions in the saved list should be checked against the pattern "dccore" in their hostname field and as soon as they find a match they should hit login and try to run come commands.

Q: Or will it be more dynamic, such as "starts with dcc"?
Ans: could be "starts with or contains" <dccore> as pattern , match against the saved sessions hostnames and based on the match run a login script with some commands.

Regds,
Faiz
Reply With Quote
  #8  
Old 04-14-2016, 11:05 AM
jdev's Avatar
jdev jdev is offline
VanDyke Technical Support
 
Join Date: Nov 2003
Location: Albuquerque, NM
Posts: 1,099
Faiz,

SecureCRT doesn't provide a way to natively iterate through the sessions saved in the Session Manager, but I've created a feature request so that this might be possible for you to accomplish natively within SecureCRT's scripting API.

In the mean time, if you're brave, and you have a default configuration, you can get a reference to the configuration folder by querying the registry, then using the file system object to iterate over your existing session.ini files to perform a pattern match on the actual session.ini file name.

We don't have a concrete example of how to do this yet, but if time allows, we may post in the future an example of how this might be done.

--Jake
__________________
Jake Devenport
VanDyke Software
Technical Support
YouTube Channel: https://www.youtube.com/vandykesoftware
Email: support@vandyke.com
Web: https://www.vandyke.com/support
Reply With Quote
  #9  
Old 04-25-2016, 02:54 AM
faiz_usmani faiz_usmani is offline
Registered User
 
Join Date: Apr 2016
Posts: 7
Hi Jake, Brenda,

Thats really nice of you to accomodate this feature enhancement in the tool for future. However do you have any sort of example where it can do the checks on current "session.ini" file? if not, can it check the hostname in any other format like pattern match in an .xlsx file?

Regds,
Farhan J.
Reply With Quote
  #10  
Old 04-25-2016, 08:08 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi Farhan,

In that case, to check current session's hostname, the information posted in response to Sascha's inquiry in this same thread is relevant.
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #11  
Old 05-04-2016, 09:45 AM
faiz_usmani faiz_usmani is offline
Registered User
 
Join Date: Apr 2016
Posts: 7
hi Brenda,
I have tried to use that script but it hasnt done anything. Do I need to modify it and save it with some different extension to make it work?

Regds,
Faiz
Reply With Quote
  #12  
Old 05-04-2016, 10:44 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi Faiz,

Yes, it's a Python example, so you would use ScriptName.py.

A VBScript version would not be all that different (ScriptName.vbs):

Code:
Set objTab = crt.GetScriptTab
Set objConfig = objTab.Session.Config
strHostname = objConfig.GetOption("Hostname")

MsgBox "Hostname is: " & strHostname
Does this help?
__________________
Thanks,
--Brenda

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #13  
Old 08-04-2016, 06:46 AM
faiz_usmani faiz_usmani is offline
Registered User
 
Join Date: Apr 2016
Posts: 7
Sorry guys that didnt work either.
Reply With Quote
  #14  
Old 08-04-2016, 10:12 AM
bgagnon bgagnon is offline
VanDyke Technical Support
 
Join Date: Oct 2008
Posts: 4,636
Hi faiz_usmani,

Please elaborate on what you mean by "didn't work either".

Did you get an error? (If so, what is the error?)

Did the command you expected to be sent to the remote not get sent?

Or ... some other issue occurred?
__________________
Thanks,
--Brenda

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

Thread Tools
Display Modes

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:13 PM.