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 05-24-2012, 06:00 AM
rainman rainman is offline
Registered User
 
Join Date: Apr 2012
Posts: 16
traceroute

Hello, I want to complete a traceroute from a server to a set of IP addresses contained in a text file, and save each trace output to an individual file named by the IP address. Unfortunately it is not working the way I expect it to. The attached script will read the IP addresses and complete a traceroute and output all IP addresses trace result to the screen and at the same time the script creates one .txt file in the directory C:\temp and will add the first trace result to the text file only. No other text files are created. Can someone please advise what I am doing wrong here please ? Thanks.


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

' Turn on synchronous mode while performing Send/Wait sequences
' so no input is missed.
crt.Screen.Synchronous = True

Sub Main

'read file with IP and set path
Const DEVICE_FILE_PATH = "c:\temp\devices.txt"

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

Dim fil
Set fil = fso.OpenTextFile(DEVICE_FILE_PATH)

Dim ip

Dim cnxnString

Dim logfile
logfile = ("C:\temp\" & ip & ".txt")
crt.Session.LogFileName = logfile
crt.Session.Log True

While Not fil.AtEndOfStream
ip = fil.ReadLine
cnxnString = "/usr/sbin/traceroute " & ip & vbCr

'Connect
crt.Screen.Send cnxnString
crt.Screen.WaitForString "servername$"
crt.Screen.Send vbCr

' Stop logging
crt.Session.Log False

' Turn off synchronous mode
crt.Screen.Synchronous = false

crt.Screen.WaitForString "servername$"

wend
crt.Screen.Synchronous = False
End Sub
Reply With Quote
  #2  
Old 05-24-2012, 07:57 AM
ajrees ajrees is offline
Registered User
 
Join Date: May 2006
Posts: 8
rainman,

I believe the problem is that you are initializing the logging outside your while loop.

Try this reordered code.

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

' Turn on synchronous mode while performing Send/Wait sequences
' so no input is missed.
crt.Screen.Synchronous = True

Sub Main

'read file with IP and set path
Const DEVICE_FILE_PATH = "c:\temp\devices.txt"

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

Dim fil
Set fil = fso.OpenTextFile(DEVICE_FILE_PATH)

Dim ip

Dim cnxnString

Dim logfile

While Not fil.AtEndOfStream
ip = fil.ReadLine
cnxnString = "/usr/sbin/traceroute " & ip & vbCr

' set logfile and start logging
logfile = ("C:\temp\" & ip & ".txt")
crt.Session.LogFileName = logfile
crt.Session.Log True

'Connect
crt.Screen.Send cnxnString
crt.Screen.WaitForString "servername$"
crt.Screen.Send vbCr

' Stop logging
crt.Session.Log False

' Turn off synchronous mode
crt.Screen.Synchronous = false

crt.Screen.WaitForString "servername$"

wend

crt.Screen.Synchronous = False
End Sub


I don't use vbscript so I am guessing that "servername$" is the name of the server from the SecureCRT session and that the server's name is in the system prompt for the system doing the traceroute command.

Aaron
Reply With Quote
  #3  
Old 05-24-2012, 10:16 AM
rainman rainman is offline
Registered User
 
Join Date: Apr 2012
Posts: 16
Thanks Aaron, that worked perfectly.
Reply With Quote
  #4  
Old 05-07-2014, 11:21 AM
st.husaini st.husaini is offline
Registered User
 
Join Date: May 2014
Posts: 1
Thumbs up Script not working on Sun machine

Hi Guys,

Happy to find this forum.

I am also a very newbee for Expect scripting.

I found this script matches my need. I need to run traceroute for about 100 devices , but that can be saved on screen or only one file is also ok to me.

To work this, I just downloaded 'netexpect-0.21.tar.bz2' from site and installed on my SunOS server in my network.

Then I just created a file 'vi Syed_Traceroute.nexp ' and pasted the script after changing the data store and input file path as per SUN OS and saved it.




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

' Turn on synchronous mode while performing Send/Wait sequences
' so no input is missed.
crt.Screen.Synchronous = True

Sub Main

'read file with IP and set path
Const DEVICE_FILE_PATH = "/users/sh773q/Devices_List"

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

Dim fil
Set fil = fso.OpenTextFile(DEVICE_FILE_PATH)

Dim ip

Dim cnxnString

Dim logfile

While Not fil.AtEndOfStream
ip = fil.ReadLine
cnxnString = "/usr/sbin/traceroute " & ip & vbCr

' set logfile and start logging
logfile = ("/users/sh773q/ " & ip & ".txt")
crt.Session.LogFileName = logfile
crt.Session.Log True

'Connect
crt.Screen.Send cnxnString
crt.Screen.WaitForString "servername$"
crt.Screen.Send vbCr

' Stop logging
crt.Session.Log False

' Turn off synchronous mode
crt.Screen.Synchronous = false

crt.Screen.WaitForString "servername$"

wend

crt.Screen.Synchronous = False
End Sub



Now after changing the permissions of the file I run the file as below, but get an error.

"./Syed_Traceroute.nexp
./Syed_Traceroute.nexp: line 5: Turn on synchronous mode while performing Send/Wait sequences
: No such file or directory
./Syed_Traceroute.nexp: line 6: crt.Screen.Synchronous: command not found
./Syed_Traceroute.nexp: line 8: Sub: command not found
./Syed_Traceroute.nexp: line 29: read file with IP and set path
Const DEVICE_FILE_PATH = "/users/sh773q/Devices_List"

Dim fso
Set fso = CreateObject("Scripting.FileSystemObject")

Dim fil
Set fil = fso.OpenTextFile(DEVICE_FILE_PATH)

Dim ip

Dim cnxnString

Dim logfile

While Not fil.AtEndOfStream
ip = fil.ReadLine
cnxnString = "/usr/sbin/traceroute " & ip & vbCr

: No such file or directory
./Syed_Traceroute.nexp: line 30: syntax error near unexpected token `('
./Syed_Traceroute.nexp: line 30: `logfile = ("/users/sh773q/ " & ip & ".txt")' "

Will be great if some one help to know if I did follow correctly and if the script suite for SUN OS or I need to script differently.

If you give me error free script for now will be great. I actually also want to log into firewall and get 'fw ver -k ' and ' service snmpd status ' output for each firewall listed in the file.

Good links to understand and learn basic scripts will also be helpful.

Thanks all in advance,

Syed
Reply With Quote
  #5  
Old 05-07-2014, 12:01 PM
rtb rtb is offline
VanDyke Technical Support
 
Join Date: Aug 2008
Posts: 4,306
Hi Syed,

This scripting forum is specific to VanDyke Software products, and the script you are trying to run on a Sun machine is specific to SecureCRT.

If you are trying to learn how to use expect on SunOS, then you may want to find a forum specific that goal.

Additionally, the script you referenced is VBScript which I do not expect to run on SunOS.

If you have questions about SecureCRT, I can help.
__________________
--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 07:30 AM.