VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   traceroute (https://forums.vandyke.com/showthread.php?t=10488)

rainman 05-24-2012 05:00 AM

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

ajrees 05-24-2012 06:57 AM

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

rainman 05-24-2012 09:16 AM

Thanks Aaron, that worked perfectly.

st.husaini 05-07-2014 10:21 AM

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.:mad::confused:

"./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 :)

rtb 05-07-2014 11:01 AM

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.


All times are GMT -6. The time now is 08:06 PM.