Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 11-17-2010, 09:52 AM
palmaraz palmaraz is offline
Registered User
 
Join Date: Dec 2009
Posts: 3
run a script from a .txt file

I have the need to run a command "sm get mc_by_mac 0023A2FE4838" many times but with different Mac address
how can I run a list of Mac address from a .txt or an excel list


I need to save this output in a file

thanks for your help



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


crt.Screen.Send "./Demon" & VbCr
crt.Screen.WaitForString "DeMon:"
crt.Screen.Send "sm get mc_by_mac 0023A2FE4838" & VbCr
crt.Screen.WaitForString ":"
Reply With Quote
  #2  
Old 11-17-2010, 11:25 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi palmaraz,

Thanks for the question. I would suggest reading the data from the file that has the MAC addresses, and altering the line of your script that is sending the command. For example:
Code:
crt.Screen.Send "sm get mc_by_mac" & strMAC & VbCr
Have you had a chance to take a look at the scripting manual? Chapter 7.1 discusses various logging options, and Chapter 7.2 discusses reading data from a file for use in a script. You can download the scripting manual from the following location:
http://www.vandyke.com/support/tips/...ing/index.html
Is this information helpful as you continue to write your script?
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
Old 11-18-2010, 09:57 AM
palmaraz palmaraz is offline
Registered User
 
Join Date: Dec 2009
Posts: 3
thanks in advance, but I'm not good programming, I donīt really Know how to make a script, I am a technician, but I will try to learn VB script to understand that.
Reply With Quote
  #4  
Old 11-18-2010, 11:08 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi palmaraz,

Thanks for the update. If you have any SecureCRT API scripting questions as you continue to create your script, please feel free to post them here.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #5  
Old 01-05-2011, 09:16 AM
palmaraz palmaraz is offline
Registered User
 
Join Date: Dec 2009
Posts: 3
Thanks.. I have done the scripts and it is working.
this script run a command from a list of MAC ADDRESSS


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

' This script demonstrates how to open a text file and read it line by
' line to a server.

' Constants used by OpenTextFile()
'
Const ForReading = 1
Const ForWriting = 2

Sub Main

Dim fso, file, str
Set fso = CreateObject("Scripting.FileSystemObject")

' Note: A runtime exception will be generated if 'input.txt' doesn't exist.
'
Set file = fso.OpenTextFile("c:\Documents and Settings\palmaraz\My Documents\listademacs.txt", ForReading, False)

Do While file.AtEndOfStream <> True

str = file.Readline

' Send the line with an appended CR
'
crt.Screen.Send "sm get mc_by_mac " & str & Chr(13)

Loop

End Sub
Reply With Quote
  #6  
Old 01-05-2011, 09:29 AM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,305
Hi palmaraz,

Thanks for the update and posting your working script. I am glad to hear that you were able to accomplish your scripting goal.
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #7  
Old 02-20-2019, 03:32 PM
Heavymetalmak Heavymetalmak is offline
Registered User
 
Join Date: Feb 2019
Posts: 3
I have a related question to the OP. My scenario is similar, except I want to prompt to select the file with data to be read and sent to screen. I cannot figure out how to get a script to allow a user to browse and select a file from the PC. Any thoughts? I'd theoretically be able to use majority of the above script otherwise.

Thanks!
Reply With Quote
  #8  
Old 02-20-2019, 04:58 PM
berdmann berdmann is offline
VanDyke Technical Support
 
Join Date: Aug 2017
Posts: 441
Hi Heavymetalmak,

You can use the FileOpenDialog method to display a file browse dialog from which a user can select a single file.

For example:

Code:
' Browse for a file of any type

filePath = crt.Dialog.FileOpenDialog("Please select a file")
Please refer to SecureCRT's Help for additional information.
__________________
Thanks,
--Brittney

VanDyke Software
Technical Support
support@vandyke.com
(505) 332-5730
Reply With Quote
  #9  
Old 02-20-2019, 07:24 PM
Heavymetalmak Heavymetalmak is offline
Registered User
 
Join Date: Feb 2019
Posts: 3
Thank you very much! I've been looking for this for 2 weeks. Not well versed in vb nor vbscript. Was about to give up and use python.
Reply With Quote
  #10  
Old 02-21-2019, 09:05 AM
berdmann berdmann is offline
VanDyke Technical Support
 
Join Date: Aug 2017
Posts: 441
Hi Heavymetalmak,

I am glad to hear that FileOpenDialog did the trick! SecureCRT's Help is the best reference for scripting, though we also have script examples available for review on our Forums!

https://forums.vandyke.com/forumdisplay.php?f=14

You may also want to take a look at our VBScript Guide!

https://www.vandyke.com/support/tips...ing/index.html

Have a great day!
__________________
Thanks,
--Brittney

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

Last edited by berdmann; 02-21-2019 at 09:16 AM.
Reply With Quote
  #11  
Old 02-21-2019, 11:39 AM
Heavymetalmak Heavymetalmak is offline
Registered User
 
Join Date: Feb 2019
Posts: 3
Again, let me say thanks for the help. Here was my final script, while not using the exact same dialog, it did the trick. My goal is to be able to run a script that will open a text file which contains server commands with specific variables, and send these commands line by line to server. I already log the output using the logfile from initial session startup.

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

crt.Screen.Synchronous = True

Sub Main
Dim objFileToRead, fileLocation, strLine, counter1

' Browse for a file of any type
fileLocation = crt.Dialog.FileOpenDialog("Please select a file")

Set objFileToRead = CreateObject("Scripting.FileSystemObject").OpenTextFile(fileLocation,1)

counter1 = 1
'Read the file line by line to input my commands listed in file one at a time
do while not objFileToRead.AtEndOfStream

strLine = objFileToRead.ReadLine()

' Send the line with an appended CR
crt.Screen.Send strLine & chr(13)
crt.Screen.WaitForString "Command Executed", "10"

loop

objFileToRead.Close

Set objFileToRead = Nothing
crt.Dialog.MessageBox("Script is Complete!")

End Sub
Reply With Quote
Reply

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 03:27 PM.