cpatte7372
asked on
VB Script Activation Problem
Hello Experts,
Can someone please tell me why the script will work for
CaptureJustTheLinesWeCareA bout
but won't work for:
CaptureJustTheLinesWeCareA bout2
Cheers
P.S.
If you can think of a more elegant / streamlined way of achieving the same result without so much code that would be great also.
Cheers
Can someone please tell me why the script will work for
CaptureJustTheLinesWeCareA
but won't work for:
CaptureJustTheLinesWeCareA
# $language = "VBScript"
# $interface = "1.0"
' ASSUMPTION: file being 'tailed' contains information
' similar to:
' Jan 5 18:26:13 device01 9927: Jan 5 18:26:12: %LINK-3-UPDOWN: Interface POS5/2, changed state to down
' Jan 5 18:26:47 device02 6332: Jan 5 18:26:46.243: %LINK-3-UPDOWN: Interface GigabitEthernet3/1, changed state to down
' Jan 5 18:28:40 device01 9937: Jan 5 18:28:39: %LINK-3-UPDOWN: Interface POS5/2, changed state to down
Dim g_fso, g_shell
Set g_fso = CreateObject("Scripting.FileSystemObject")
Set g_shell = CreateObject("WScript.Shell")
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim g_szLogFile, g_szFirstLogFilePath, objTab
g_szLogFile = GetMyDocumentsFolder & "\Command#__NUM___Results.txt"
Set objTab = crt.GetScriptTab
Dim g_vCommands(100)
g_vCommands(0) = "show ip int brief"
g_vCommands(1) = "show cdp neighbor"
' .
' .
' .
Dim h_vCommands(100)
h_vCommands(0) = "term len 0"
h_vCommands(1) = "show run"
' .
' .
' .
Sub Main()
' Make sure that we are running in Synchronous mode so
' that when WaitForStrings() finds something, we can
' capture the current line without risk of it already
' having flown by on the screen. This slows things down
' a bit, but provides insurance against errors due to
' SecureCRT and the script running asynchronously.
crt.Screen.Synchronous = true
' Start tailing a file...
crt.Screen.Send "tail tailfile.txt" & vbcr
' Example #1: Uses WaitForString to look for just the text
' we care about. Once the text is found, the
' line on which the text was located is captured
' and a piece of information is parsed using the
' Split() builtin VBScript method.
CaptureJustTheLinesWeCareAbout
CaptureJustTheLinesWeCareAbout2
' Example #2: Uses WaitForString to detect when every new line
' arrives from the remote. Each line of text is
' captured, and the Instr() builtin VBScript
' function is used to detect the presence of the
' specific text we care about. Iff it is present,
' the Split() builtin VBScript method is used to
' parse out the relevant piece of information.
'
' The benefit of this method over
' CaptureJustTheLinesWeCareAbout is that we
' can retrieve information from the line if
' the text we care about comes prior to the
' relevant piece of information that we would
' like to display as part of our notification.
'
' To enable this example, comment out the statement
' on line 29 and uncomment the line below:
' CaptureAllLinesAndSearchForTextWeCareAbout
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub CaptureJustTheLinesWeCareAbout()
MsgBox "Capturing just the lines we care about"
do
' Look for specific output
crt.Screen.WaitForString "changed state to down"
' Once specific output is found, capture the line
' of text on which the "changed to state down" string
' was located.
szCurrentLine = crt.Screen.Get(crt.Screen.CurrentRow, _
0, _
crt.Screen.CurrentRow, _
crt.Screen.Columns)
' Trim off any leading or training spaces
szCurrentLine = Trim(szCurrentLine)
' Use the Split() method (builtin VBScript method)
' to get at the component we care about (deviceID)
vElements = Split(szCurrentLine, " ")
for each x in vElements
'document.write(x & "<br />")
next
MsgBox "Device """ & vElements(3) & """ just went down."
g_szLogFile = GetMyDocumentsFolder & "\Command#__NUM___Results.txt"
Set objTab = crt.GetScriptTab
LogOutputOfSpecificCommandUseReadString
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & """ just went down."
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & "is " vElements(6)"
Loop
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub CaptureJustTheLinesWeCareAbout2()
MsgBox "Capturing just the lines we care about"
do
' Look for specific output
crt.Screen.WaitForString "changed state to up"
' Once specific output is found, capture the line
' of text on which the "changed to state down" string
' was located.
szCurrentLine = crt.Screen.Get(crt.Screen.CurrentRow, _
0, _
crt.Screen.CurrentRow, _
crt.Screen.Columns)
' Trim off any leading or training spaces
szCurrentLine = Trim(szCurrentLine)
' Use the Split() method (builtin VBScript method)
' to get at the component we care about (deviceID)
vElements = Split(szCurrentLine, " ")
for each x in vElements
'document.write(x & "<br />")
next
'MsgBox "Device """ & vElements(3) & """ just went down."
g_szLogFile = GetMyDocumentsFolder & "\Command#__NUM___Results.txt"
Set objTab = crt.GetScriptTab
LogOutputOfSpecificCommandUseReadString2
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & """ just went down."
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & "is " vElements(6)"
Loop
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub LogOutputOfSpecificCommandUseReadString()
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(g_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array g_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array g_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub LogOutputOfSpecificCommandUseReadString2()
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(h_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array h_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array h_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function GetMyDocumentsFolder()
Dim myShell
Set myShell = CreateObject("WScript.Shell")
GetMyDocumentsFolder = myShell.SpecialFolders("MyDocuments")
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function NN(nNumber, nDesiredDigits)
' Normalizes a single digit number to have nDesiredDigits 0s in front of it
Dim nIndex, nOffbyDigits, szResult
nOffbyDigits = nDesiredDigits - len(nNumber)
szResult = nNumber
For nIndex = 1 to nOffByDigits
szResult = "0" & szResult
Next
NN = szResult
End Function
Cheers
P.S.
If you can think of a more elegant / streamlined way of achieving the same result without so much code that would be great also.
Cheers
what is not working?
ASKER
Hi Sedgwick
Taking a look at line 55 to 61 the Example Uses WaitForString to look for just the text I care about. Once the text is found, the line on which the text was located is captured and a piece of information is parsed using the Split() builtin VBScript method.(I actually don't know what Split() builtin VBScript is.
If the text 'changed state to down' appears then
Sub CaptureJustTheLinesWeCareA bout() is invoked,
However, if the text 'changed state to up' appears
Sub CaptureJustTheLinesWeCareA bout2(), isn't invoked.
Does that make sense?
Cheers
Carlton
Taking a look at line 55 to 61 the Example Uses WaitForString to look for just the text I care about. Once the text is found, the line on which the text was located is captured and a piece of information is parsed using the Split() builtin VBScript method.(I actually don't know what Split() builtin VBScript is.
If the text 'changed state to down' appears then
Sub CaptureJustTheLinesWeCareA
However, if the text 'changed state to up' appears
Sub CaptureJustTheLinesWeCareA
Does that make sense?
Cheers
Carlton
in the post line 55 to 61 has alot of commented lines besides 2 calls to CaptureJustTheLinesWeCareA bout and CaptureJustTheLinesWeCareA bout2.
are we watching the same script?
btw, split function splits the string to string array based on given delimiter.
for example:
dim words = split("changed state to down"," ")
the 2nd parameter is the delimiter, in this case is a space.
so u ended up having an array with 4 words:
changed
state
to
down
are we watching the same script?
btw, split function splits the string to string array based on given delimiter.
for example:
dim words = split("changed state to down"," ")
the 2nd parameter is the delimiter, in this case is a space.
so u ended up having an array with 4 words:
changed
state
to
down
ASKER
Hi Sedgwick,
Yes we're watching the same script. I talked about lines 55 to 61 to try and make myself understood - failed at that :-)
Anyhow, the problem is 'calls' to 'CaptureJustTheLinesWeCare About' work but calls to 'CaptureJustTheLinesWeCare About2', don't work
Yes we're watching the same script. I talked about lines 55 to 61 to try and make myself understood - failed at that :-)
Anyhow, the problem is 'calls' to 'CaptureJustTheLinesWeCare
found the bug, replace line 323 from
to
szCommand = Trim(h_vCommands(nIndex))
to
szCommand = Trim(g_vCommands(nIndex))
ASKER
Hi Sedgwick,
Going to try that now, but I'm not sure that is the problem . uhmmmm
Going to try that now, but I'm not sure that is the problem . uhmmmm
ASKER
Hi Sedgwick,
Just as I thought.
The change resulted in the text 'change state to down' to call Sub CaptureJustTheLinesWeCareA bout2()
whereas 'change state to down' should call CaptureJustTheLinesWeCareA bout() and 'changed state to up' should call CaptureJustTheLinesWeCareA bout2()
Just as I thought.
The change resulted in the text 'change state to down' to call Sub CaptureJustTheLinesWeCareA
whereas 'change state to down' should call CaptureJustTheLinesWeCareA
ASKER
Sedgwick
Is the problem that I have to Dims'
Dim g_vCommands(100)
g_vCommands(0) = "show ip int brief"
g_vCommands(1) = "show cdp neighbor"
' .
' .
' .
Dim h_vCommands(100)
h_vCommands(0) = "term len 0"
h_vCommands(1) = "show run"
Is the problem that I have to Dims'
Dim g_vCommands(100)
g_vCommands(0) = "show ip int brief"
g_vCommands(1) = "show cdp neighbor"
' .
' .
' .
Dim h_vCommands(100)
h_vCommands(0) = "term len 0"
h_vCommands(1) = "show run"
i fixed it:
# $language = "VBScript"
# $interface = "1.0"
' ASSUMPTION: file being 'tailed' contains information
' similar to:
' Jan 5 18:26:13 device01 9927: Jan 5 18:26:12: %LINK-3-UPDOWN: Interface POS5/2, changed state to down
' Jan 5 18:26:47 device02 6332: Jan 5 18:26:46.243: %LINK-3-UPDOWN: Interface GigabitEthernet3/1, changed state to down
' Jan 5 18:28:40 device01 9937: Jan 5 18:28:39: %LINK-3-UPDOWN: Interface POS5/2, changed state to down
Dim g_fso, g_shell
Set g_fso = CreateObject("Scripting.FileSystemObject")
Set g_shell = CreateObject("WScript.Shell")
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim g_szLogFile, g_szFirstLogFilePath, objTab
g_szLogFile = GetMyDocumentsFolder & "\Command#__NUM___Results.txt"
Set objTab = crt.GetScriptTab
Sub Main()
' Make sure that we are running in Synchronous mode so
' that when WaitForStrings() finds something, we can
' capture the current line without risk of it already
' having flown by on the screen. This slows things down
' a bit, but provides insurance against errors due to
' SecureCRT and the script running asynchronously.
crt.Screen.Synchronous = true
' Start tailing a file...
crt.Screen.Send "tail tailfile.txt" & vbcr
' Example #1: Uses WaitForString to look for just the text
' we care about. Once the text is found, the
' line on which the text was located is captured
' and a piece of information is parsed using the
' Split() builtin VBScript method.
CaptureJustTheLinesWeCareAbout
CaptureJustTheLinesWeCareAbout2
' Example #2: Uses WaitForString to detect when every new line
' arrives from the remote. Each line of text is
' captured, and the Instr() builtin VBScript
' function is used to detect the presence of the
' specific text we care about. Iff it is present,
' the Split() builtin VBScript method is used to
' parse out the relevant piece of information.
'
' The benefit of this method over
' CaptureJustTheLinesWeCareAbout is that we
' can retrieve information from the line if
' the text we care about comes prior to the
' relevant piece of information that we would
' like to display as part of our notification.
'
' To enable this example, comment out the statement
' on line 29 and uncomment the line below:
' CaptureAllLinesAndSearchForTextWeCareAbout
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub CaptureJustTheLinesWeCareAbout()
MsgBox "Capturing just the lines we care about"
do
' Look for specific output
crt.Screen.WaitForString "changed state to down"
' Once specific output is found, capture the line
' of text on which the "changed to state down" string
' was located.
szCurrentLine = crt.Screen.Get(crt.Screen.CurrentRow, _
0, _
crt.Screen.CurrentRow, _
crt.Screen.Columns)
' Trim off any leading or training spaces
szCurrentLine = Trim(szCurrentLine)
' Use the Split() method (builtin VBScript method)
' to get at the component we care about (deviceID)
vElements = Split(szCurrentLine, " ")
for each x in vElements
'document.write(x & "<br />")
next
MsgBox "Device """ & vElements(3) & """ just went down."
g_szLogFile = GetMyDocumentsFolder & "\Command#__NUM___Results.txt"
Set objTab = crt.GetScriptTab
LogOutputOfSpecificCommandUseReadString
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & """ just went down."
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & "is " vElements(6)"
Loop
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub CaptureJustTheLinesWeCareAbout2()
MsgBox "Capturing just the lines we care about"
do
' Look for specific output
crt.Screen.WaitForString "changed state to up"
' Once specific output is found, capture the line
' of text on which the "changed to state down" string
' was located.
szCurrentLine = crt.Screen.Get(crt.Screen.CurrentRow, _
0, _
crt.Screen.CurrentRow, _
crt.Screen.Columns)
' Trim off any leading or training spaces
szCurrentLine = Trim(szCurrentLine)
' Use the Split() method (builtin VBScript method)
' to get at the component we care about (deviceID)
vElements = Split(szCurrentLine, " ")
for each x in vElements
'document.write(x & "<br />")
next
'MsgBox "Device """ & vElements(3) & """ just went down."
g_szLogFile = GetMyDocumentsFolder & "\Command#__NUM___Results.txt"
Set objTab = crt.GetScriptTab
LogOutputOfSpecificCommandUseReadString2
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & """ just went down."
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & "is " vElements(6)"
Loop
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub LogOutputOfSpecificCommandUseReadString()
Dim g_vCommands(100)
g_vCommands(0) = "show ip int brief"
g_vCommands(1) = "show cdp neighbor"
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(g_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array g_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array g_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub LogOutputOfSpecificCommandUseReadString2()
Dim h_vCommands(100)
h_vCommands(0) = "term len 0"
h_vCommands(1) = "show run"
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(h_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array h_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array h_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function GetMyDocumentsFolder()
Dim myShell
Set myShell = CreateObject("WScript.Shell")
GetMyDocumentsFolder = myShell.SpecialFolders("MyDocuments")
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function NN(nNumber, nDesiredDigits)
' Normalizes a single digit number to have nDesiredDigits 0s in front of it
Dim nIndex, nOffbyDigits, szResult
nOffbyDigits = nDesiredDigits - len(nNumber)
szResult = nNumber
For nIndex = 1 to nOffByDigits
szResult = "0" & szResult
Next
NN = szResult
End Function
ASKER
Hi Sedgwick,
I wish you had, but the text 'changed state to down' still calls CaptureJustTheLinesWeCareA bout2(), whereas the nothing happens with the text 'changed state to up'
I wish you had, but the text 'changed state to down' still calls CaptureJustTheLinesWeCareA
the script is posted simply calls the 2 Subs one after the other.
i can't see any usage of the split() function which determines which sub is called based on which command.
i can't see any usage of the split() function which determines which sub is called based on which command.
ASKER
Hi Sedgwick
Thats a shame, because if you can't figure out I know I wont be able to. ;-(
Thats a shame, because if you can't figure out I know I wont be able to. ;-(
don't give up.
after lines 87 and 135 add debug line:
after lines 87 and 135 add debug line:
wscript.echo vElements
what do u get?
ASKER
Hi Sedgwick,
Going add it now.
I won't give up if you don't
Going add it now.
I won't give up if you don't
ASKER
Try changing the suggested line:
wscript.echo vElements
to:
MsgBox vElements
~bp
wscript.echo vElements
to:
MsgBox vElements
~bp
ASKER
Hi billprew,
Thanks for responding.
After trying your suggestion I get the following error shown in the attachment
Cheers
scripterror10.png
Thanks for responding.
After trying your suggestion I get the following error shown in the attachment
Cheers
scripterror10.png
Okay, makes sense, it's an array, I wasn't looking at the code other than that single line before. Try this:
MsgBox Join(vElements, "|")
~bp
MsgBox Join(vElements, "|")
~bp
ASKER
Hi billprew,
That is working, however we appear to be at the same place we have been.
Let me try to explain'
When the following text appears 'changed state to down' the script calls CaptureJustTheLinesWeCareA bout().
However, when the text 'changed state to up' appears the script won't call CaptureJustTheLinesWeCareA bout2()
The Expert that has been currently working on this has tried very hard, but it appears to be a problem to get the script to call CaptureJustTheLinesWeCareA bout2()
Cheers
That is working, however we appear to be at the same place we have been.
Let me try to explain'
When the following text appears 'changed state to down' the script calls CaptureJustTheLinesWeCareA
However, when the text 'changed state to up' appears the script won't call CaptureJustTheLinesWeCareA
The Expert that has been currently working on this has tried very hard, but it appears to be a problem to get the script to call CaptureJustTheLinesWeCareA
Cheers
ASKER
Billprew,
The following Msgbox appears when CaptureJustTheLinesWeCareA bout() is called, see attachment..
scripterror101.png
The following Msgbox appears when CaptureJustTheLinesWeCareA
scripterror101.png
ASKER
Sedgwick
Have you given up?
Have you given up?
nop, i've been crazy busy at work had no time to even review the comments.
try something else, instead of using separate crt.Screen.WaitForString for "changed state to up" and "changed state to down", try use
Dim result = crt.Screen.WaitForStrings( "changed state to up","changed state to down"):
try something else, instead of using separate crt.Screen.WaitForString for "changed state to up" and "changed state to down", try use
Dim result = crt.Screen.WaitForStrings(
# $language = "VBScript"
# $interface = "1.0"
' ASSUMPTION: file being 'tailed' contains information
' similar to:
' Jan 5 18:26:13 device01 9927: Jan 5 18:26:12: %LINK-3-UPDOWN: Interface POS5/2, changed state to down
' Jan 5 18:26:47 device02 6332: Jan 5 18:26:46.243: %LINK-3-UPDOWN: Interface GigabitEthernet3/1, changed state to down
' Jan 5 18:28:40 device01 9937: Jan 5 18:28:39: %LINK-3-UPDOWN: Interface POS5/2, changed state to down
Dim g_fso, g_shell
Set g_fso = CreateObject("Scripting.FileSystemObject")
Set g_shell = CreateObject("WScript.Shell")
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim g_szLogFile, g_szFirstLogFilePath, objTab
g_szLogFile = GetMyDocumentsFolder & "\Command#__NUM___Results.txt"
Set objTab = crt.GetScriptTab
Dim g_vCommands(100)
g_vCommands(0) = "show ip int brief"
g_vCommands(1) = "show cdp neighbor"
' .
' .
' .
Dim h_vCommands(100)
h_vCommands(0) = "term len 0"
h_vCommands(1) = "show run"
' .
' .
' .
Sub Main()
' Make sure that we are running in Synchronous mode so
' that when WaitForStrings() finds something, we can
' capture the current line without risk of it already
' having flown by on the screen. This slows things down
' a bit, but provides insurance against errors due to
' SecureCRT and the script running asynchronously.
crt.Screen.Synchronous = true
' Start tailing a file...
crt.Screen.Send "tail tailfile.txt" & vbcr
' Example #1: Uses WaitForString to look for just the text
' we care about. Once the text is found, the
' line on which the text was located is captured
' and a piece of information is parsed using the
' Split() builtin VBScript method.
CaptureJustTheLinesWeCareAbout
' Example #2: Uses WaitForString to detect when every new line
' arrives from the remote. Each line of text is
' captured, and the Instr() builtin VBScript
' function is used to detect the presence of the
' specific text we care about. Iff it is present,
' the Split() builtin VBScript method is used to
' parse out the relevant piece of information.
'
' The benefit of this method over
' CaptureJustTheLinesWeCareAbout is that we
' can retrieve information from the line if
' the text we care about comes prior to the
' relevant piece of information that we would
' like to display as part of our notification.
'
' To enable this example, comment out the statement
' on line 29 and uncomment the line below:
' CaptureAllLinesAndSearchForTextWeCareAbout
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub CaptureJustTheLinesWeCareAbout()
MsgBox "Capturing just the lines we care about"
do
' Look for specific output
dim result = crt.Screen.WaitForStrings("changed state to up","changed state to down")
' Once specific output is found, capture the line
' of text on which the "changed to state down" string
' was located.
szCurrentLine = crt.Screen.Get(crt.Screen.CurrentRow, _
0, _
crt.Screen.CurrentRow, _
crt.Screen.Columns)
' Trim off any leading or training spaces
szCurrentLine = Trim(szCurrentLine)
' Use the Split() method (builtin VBScript method)
' to get at the component we care about (deviceID)
vElements = Split(szCurrentLine, " ")
for each x in vElements
'document.write(x & "<br />")
next
'MsgBox "Device """ & vElements(3) & """ just went down."
g_szLogFile = GetMyDocumentsFolder & "\Command#__NUM___Results.txt"
Set objTab = crt.GetScriptTab
select case result
case 1
LogOutputOfSpecificCommandUseReadString
case 2
LogOutputOfSpecificCommandUseReadString2
end select
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & """ just went down."
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & "is " vElements(6)"
Loop
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub LogOutputOfSpecificCommandUseReadString()
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(g_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array g_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array g_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub LogOutputOfSpecificCommandUseReadString2()
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(h_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array h_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array h_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
Function GetMyDocumentsFolder()
Dim myShell
Set myShell = CreateObject("WScript.Shell")
GetMyDocumentsFolder = myShell.SpecialFolders("MyDocuments")
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function NN(nNumber, nDesiredDigits)
' Normalizes a single digit number to have nDesiredDigits 0s in front of it
Dim nIndex, nOffbyDigits, szResult
nOffbyDigits = nDesiredDigits - len(nNumber)
szResult = nNumber
For nIndex = 1 to nOffByDigits
szResult = "0" & szResult
Next
NN = szResult
End Function
ASKER
Hi Sedgwick,
I'm pleased you're sticking with me on this.
Anyway, I getting the follow error, see attached
scripterror12.png
I'm pleased you're sticking with me on this.
Anyway, I getting the follow error, see attached
scripterror12.png
CAn u post the script?
Line 91 in my post refer to a comment and not the discussed function.
Line 91 in my post refer to a comment and not the discussed function.
ASKER
Hi Sedgwick,
I'm using the following script:
I'm using the following script:
# $language = "VBScript"
# $interface = "1.0"
' ASSUMPTION: file being 'tailed' contains information
' similar to:
' Jan 5 18:26:13 device01 9927: Jan 5 18:26:12: %LINK-3-UPDOWN: Interface POS5/2, changed state to down
' Jan 5 18:26:47 device02 6332: Jan 5 18:26:46.243: %LINK-3-UPDOWN: Interface GigabitEthernet3/1, changed state to down
' Jan 5 18:28:40 device01 9937: Jan 5 18:28:39: %LINK-3-UPDOWN: Interface POS5/2, changed state to down
Dim g_fso, g_shell
Set g_fso = CreateObject("Scripting.FileSystemObject")
Set g_shell = CreateObject("WScript.Shell")
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim g_szLogFile, g_szFirstLogFilePath, objTab
g_szLogFile = GetMyDocumentsFolder & "\Command#__NUM___Results.txt"
Set objTab = crt.GetScriptTab
Dim g_vCommands(100)
g_vCommands(0) = "show ip int brief"
g_vCommands(1) = "show cdp neighbor"
' .
' .
' .
Dim h_vCommands(100)
h_vCommands(0) = "term len 0"
h_vCommands(1) = "show run"
' .
' .
' .
Sub Main()
' Make sure that we are running in Synchronous mode so
' that when WaitForStrings() finds something, we can
' capture the current line without risk of it already
' having flown by on the screen. This slows things down
' a bit, but provides insurance against errors due to
' SecureCRT and the script running asynchronously.
crt.Screen.Synchronous = true
' Start tailing a file...
crt.Screen.Send "tail tailfile.txt" & vbcr
' Example #1: Uses WaitForString to look for just the text
' we care about. Once the text is found, the
' line on which the text was located is captured
' and a piece of information is parsed using the
' Split() builtin VBScript method.
CaptureJustTheLinesWeCareAbout
' Example #2: Uses WaitForString to detect when every new line
' arrives from the remote. Each line of text is
' captured, and the Instr() builtin VBScript
' function is used to detect the presence of the
' specific text we care about. Iff it is present,
' the Split() builtin VBScript method is used to
' parse out the relevant piece of information.
'
' The benefit of this method over
' CaptureJustTheLinesWeCareAbout is that we
' can retrieve information from the line if
' the text we care about comes prior to the
' relevant piece of information that we would
' like to display as part of our notification.
'
' To enable this example, comment out the statement
' on line 29 and uncomment the line below:
' CaptureAllLinesAndSearchForTextWeCareAbout
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub CaptureJustTheLinesWeCareAbout()
MsgBox "Capturing just the lines we care about"
do
' Look for specific output
dim result = crt.Screen.WaitForStrings("changed state to up","changed state to down")
' Once specific output is found, capture the line
' of text on which the "changed to state down" string
' was located.
szCurrentLine = crt.Screen.Get(crt.Screen.CurrentRow, _
0, _
crt.Screen.CurrentRow, _
crt.Screen.Columns)
' Trim off any leading or training spaces
szCurrentLine = Trim(szCurrentLine)
' Use the Split() method (builtin VBScript method)
' to get at the component we care about (deviceID)
vElements = Split(szCurrentLine, " ")
for each x in vElements
'document.write(x & "<br />")
next
'MsgBox "Device """ & vElements(3) & """ just went down."
g_szLogFile = GetMyDocumentsFolder & "\Command#__NUM___Results.txt"
Set objTab = crt.GetScriptTab
select case result
case 1
LogOutputOfSpecificCommandUseReadString
case 2
LogOutputOfSpecificCommandUseReadString2
end select
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & """ just went down."
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & "is " vElements(6)"
Loop
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub LogOutputOfSpecificCommandUseReadString()
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(g_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array g_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array g_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub LogOutputOfSpecificCommandUseReadString2()
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(h_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array h_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array h_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
Function GetMyDocumentsFolder()
Dim myShell
Set myShell = CreateObject("WScript.Shell")
GetMyDocumentsFolder = myShell.SpecialFolders("MyDocuments")
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function NN(nNumber, nDesiredDigits)
' Normalizes a single digit number to have nDesiredDigits 0s in front of it
Dim nIndex, nOffbyDigits, szResult
nOffbyDigits = nDesiredDigits - len(nNumber)
szResult = nNumber
For nIndex = 1 to nOffByDigits
szResult = "0" & szResult
Next
NN = szResult
End Function
i change the function call to accept array, try now:
# $language = "VBScript"
# $interface = "1.0"
' ASSUMPTION: file being 'tailed' contains information
' similar to:
' Jan 5 18:26:13 device01 9927: Jan 5 18:26:12: %LINK-3-UPDOWN: Interface POS5/2, changed state to down
' Jan 5 18:26:47 device02 6332: Jan 5 18:26:46.243: %LINK-3-UPDOWN: Interface GigabitEthernet3/1, changed state to down
' Jan 5 18:28:40 device01 9937: Jan 5 18:28:39: %LINK-3-UPDOWN: Interface POS5/2, changed state to down
Dim g_fso, g_shell
Set g_fso = CreateObject("Scripting.FileSystemObject")
Set g_shell = CreateObject("WScript.Shell")
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim g_szLogFile, g_szFirstLogFilePath, objTab
g_szLogFile = GetMyDocumentsFolder & "\Command#__NUM___Results.txt"
Set objTab = crt.GetScriptTab
Dim g_vCommands(100)
g_vCommands(0) = "show ip int brief"
g_vCommands(1) = "show cdp neighbor"
' .
' .
' .
Dim h_vCommands(100)
h_vCommands(0) = "term len 0"
h_vCommands(1) = "show run"
' .
' .
' .
Sub Main()
' Make sure that we are running in Synchronous mode so
' that when WaitForStrings() finds something, we can
' capture the current line without risk of it already
' having flown by on the screen. This slows things down
' a bit, but provides insurance against errors due to
' SecureCRT and the script running asynchronously.
crt.Screen.Synchronous = true
' Start tailing a file...
crt.Screen.Send "tail tailfile.txt" & vbcr
' Example #1: Uses WaitForString to look for just the text
' we care about. Once the text is found, the
' line on which the text was located is captured
' and a piece of information is parsed using the
' Split() builtin VBScript method.
CaptureJustTheLinesWeCareAbout
' Example #2: Uses WaitForString to detect when every new line
' arrives from the remote. Each line of text is
' captured, and the Instr() builtin VBScript
' function is used to detect the presence of the
' specific text we care about. Iff it is present,
' the Split() builtin VBScript method is used to
' parse out the relevant piece of information.
'
' The benefit of this method over
' CaptureJustTheLinesWeCareAbout is that we
' can retrieve information from the line if
' the text we care about comes prior to the
' relevant piece of information that we would
' like to display as part of our notification.
'
' To enable this example, comment out the statement
' on line 29 and uncomment the line below:
' CaptureAllLinesAndSearchForTextWeCareAbout
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub CaptureJustTheLinesWeCareAbout()
MsgBox "Capturing just the lines we care about"
do
' Look for specific output
Dim vWaitFors
vWaitFors = Array("changed state to up","changed state to down")
dim result = crt.Screen.WaitForStrings(vWaitFors, 10)
' Once specific output is found, capture the line
' of text on which the "changed to state down" string
' was located.
szCurrentLine = crt.Screen.Get(crt.Screen.CurrentRow, _
0, _
crt.Screen.CurrentRow, _
crt.Screen.Columns)
' Trim off any leading or training spaces
szCurrentLine = Trim(szCurrentLine)
' Use the Split() method (builtin VBScript method)
' to get at the component we care about (deviceID)
vElements = Split(szCurrentLine, " ")
for each x in vElements
'document.write(x & "<br />")
next
'MsgBox "Device """ & vElements(3) & """ just went down."
g_szLogFile = GetMyDocumentsFolder & "\Command#__NUM___Results.txt"
Set objTab = crt.GetScriptTab
select case result
case 1
LogOutputOfSpecificCommandUseReadString
case 2
LogOutputOfSpecificCommandUseReadString2
end select
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & """ just went down."
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & "is " vElements(6)"
Loop
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub LogOutputOfSpecificCommandUseReadString()
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(g_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array g_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array g_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub LogOutputOfSpecificCommandUseReadString2()
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(h_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array h_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array h_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
Function GetMyDocumentsFolder()
Dim myShell
Set myShell = CreateObject("WScript.Shell")
GetMyDocumentsFolder = myShell.SpecialFolders("MyDocuments")
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function NN(nNumber, nDesiredDigits)
' Normalizes a single digit number to have nDesiredDigits 0s in front of it
Dim nIndex, nOffbyDigits, szResult
nOffbyDigits = nDesiredDigits - len(nNumber)
szResult = nNumber
For nIndex = 1 to nOffByDigits
szResult = "0" & szResult
Next
NN = szResult
End Function
ASKER
Hi Sedgwick,
Thanks again for responding. I'm not getting the following error, see attached.
scripterror12.png
Thanks again for responding. I'm not getting the following error, see attached.
scripterror12.png
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sedgwick,
It appears to be working. I don't want to get to excited just yet. I want to carry out a few tests, but at the moment a sitting here with a big smile on my face :-)
It appears to be working. I don't want to get to excited just yet. I want to carry out a few tests, but at the moment a sitting here with a big smile on my face :-)
\w/
ASKER
This is beautiful. And just to think I was about to cancel my membership because I thought I could get help from other sites - nothing to do with you - I just thought I wasn't getting value for my money.
You're a star.
So, if I want to add another case would I do the following when the text "%LINK-5-CHANGED" appears:
You're a star.
So, if I want to add another case would I do the following when the text "%LINK-5-CHANGED" appears:
# $language = "VBScript"
# $interface = "1.0"
' ASSUMPTION: file being 'tailed' contains information
' similar to:
' Jan 5 18:26:13 device01 9927: Jan 5 18:26:12: %LINK-3-UPDOWN: Interface POS5/2, changed state to down
' Jan 5 18:26:47 device02 6332: Jan 5 18:26:46.243: %LINK-3-UPDOWN: Interface GigabitEthernet3/1, changed state to down
' Jan 5 18:28:40 device01 9937: Jan 5 18:28:39: %LINK-3-UPDOWN: Interface POS5/2, changed state to down
Dim g_fso, g_shell
Set g_fso = CreateObject("Scripting.FileSystemObject")
Set g_shell = CreateObject("WScript.Shell")
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim g_szLogFile, g_szFirstLogFilePath, objTab
g_szLogFile = GetMyDocumentsFolder & "\Command#__NUM___Results.txt"
Set objTab = crt.GetScriptTab
Dim g_vCommands(100)
g_vCommands(0) = "show ip int brief"
g_vCommands(1) = "show cdp neighbor"
' .
' .
' .
Dim h_vCommands(100)
h_vCommands(0) = "term len 0"
h_vCommands(1) = "show run"
h_vCommands(2) = "show ip bgp"
' .
' .
' .
Dim I_vCommands(100)
I_vCommands(0) = "term len 0"
I_vCommands(1) = "show run"
I_vCommands(2) = "show ip bgp"
' .
' .
' .
Sub Main()
' Make sure that we are running in Synchronous mode so
' that when WaitForStrings() finds something, we can
' capture the current line without risk of it already
' having flown by on the screen. This slows things down
' a bit, but provides insurance against errors due to
' SecureCRT and the script running asynchronously.
crt.Screen.Synchronous = true
' Start tailing a file...
crt.Screen.Send "tail tailfile.txt" & vbcr
' Example #1: Uses WaitForString to look for just the text
' we care about. Once the text is found, the
' line on which the text was located is captured
' and a piece of information is parsed using the
' Split() builtin VBScript method.
CaptureJustTheLinesWeCareAbout
' Example #2: Uses WaitForString to detect when every new line
' arrives from the remote. Each line of text is
' captured, and the Instr() builtin VBScript
' function is used to detect the presence of the
' specific text we care about. Iff it is present,
' the Split() builtin VBScript method is used to
' parse out the relevant piece of information.
'
' The benefit of this method over
' CaptureJustTheLinesWeCareAbout is that we
' can retrieve information from the line if
' the text we care about comes prior to the
' relevant piece of information that we would
' like to display as part of our notification.
'
' To enable this example, comment out the statement
' on line 29 and uncomment the line below:
' CaptureAllLinesAndSearchForTextWeCareAbout
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub CaptureJustTheLinesWeCareAbout()
MsgBox "Capturing just the lines we care about"
do
' Look for specific output
dim result
result = crt.Screen.WaitForStrings("changed state to up","changed state to down","%LINK-5-CHANGED")
' Once specific output is found, capture the line
' of text on which the "changed to state down" string
' was located.
szCurrentLine = crt.Screen.Get(crt.Screen.CurrentRow, _
0, _
crt.Screen.CurrentRow, _
crt.Screen.Columns)
' Trim off any leading or training spaces
szCurrentLine = Trim(szCurrentLine)
' Use the Split() method (builtin VBScript method)
' to get at the component we care about (deviceID)
vElements = Split(szCurrentLine, " ")
for each x in vElements
'document.write(x & "<br />")
next
'MsgBox "Device """ & vElements(3) & """ just went down."
g_szLogFile = GetMyDocumentsFolder & "\Command#__NUM___Results.txt"
Set objTab = crt.GetScriptTab
select case result
case 1
LogOutputOfSpecificCommandUseReadString
case 2
LogOutputOfSpecificCommandUseReadString2
end select
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & """ just went down."
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & "is " vElements(6)"
Loop
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub LogOutputOfSpecificCommandUseReadString()
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(g_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array g_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array g_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub LogOutputOfSpecificCommandUseReadString2()
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(h_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array h_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array h_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
Function GetMyDocumentsFolder()
Dim myShell
Set myShell = CreateObject("WScript.Shell")
GetMyDocumentsFolder = myShell.SpecialFolders("MyDocuments")
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub LogOutputOfSpecificCommandUseReadString3()
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(I_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array I_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array I_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function NN(nNumber, nDesiredDigits)
' Normalizes a single digit number to have nDesiredDigits 0s in front of it
Dim nIndex, nOffbyDigits, szResult
nOffbyDigits = nDesiredDigits - len(nNumber)
szResult = nNumber
For nIndex = 1 to nOffByDigits
szResult = "0" & szResult
Next
NN = szResult
End Function
yes, but check line 130.
u need to update the select case if u add more expressions for WaitForStrings() function:
u need to update the select case if u add more expressions for WaitForStrings() function:
select case result
case 1
'handle "changed state to up"
LogOutputOfSpecificCommandUseReadString
case 2
'handle "changed state to down"
LogOutputOfSpecificCommandUseReadString2
case 3
'handle "%LINK-5-CHANGED"
end select
ASKER
Sedgwick,
Don't I need to also add
LogOutputOfSpecificCommand UseReadStr ing3
Don't I need to also add
LogOutputOfSpecificCommand
ASKER
Hi Sedgwick,
I amended the script as you suggested, however it didn't work:
I amended the script as you suggested, however it didn't work:
# $language = "VBScript"
# $interface = "1.0"
' ASSUMPTION: file being 'tailed' contains information
' similar to:
' Jan 5 18:26:13 device01 9927: Jan 5 18:26:12: %LINK-3-UPDOWN: Interface POS5/2, changed state to down
' Jan 5 18:26:47 device02 6332: Jan 5 18:26:46.243: %LINK-3-UPDOWN: Interface GigabitEthernet3/1, changed state to down
' Jan 5 18:28:40 device01 9937: Jan 5 18:28:39: %LINK-3-UPDOWN: Interface POS5/2, changed state to down
Dim g_fso, g_shell
Set g_fso = CreateObject("Scripting.FileSystemObject")
Set g_shell = CreateObject("WScript.Shell")
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim g_szLogFile, g_szFirstLogFilePath, objTab
g_szLogFile = GetMyDocumentsFolder & "\Command#__NUM___Results.txt"
Set objTab = crt.GetScriptTab
Dim g_vCommands(100)
g_vCommands(0) = "show ip int brief"
g_vCommands(1) = "show cdp neighbor"
' .
' .
' .
Dim h_vCommands(100)
h_vCommands(0) = "term len 0"
h_vCommands(1) = "show run"
h_vCommands(2) = "show ip bgp"
' .
' .
' .
Dim I_vCommands(100)
I_vCommands(0) = "term len 0"
I_vCommands(1) = "show ip traffic"
I_vCommands(2) = "show ip pim"
' .
' .
' .
Sub Main()
' Make sure that we are running in Synchronous mode so
' that when WaitForStrings() finds something, we can
' capture the current line without risk of it already
' having flown by on the screen. This slows things down
' a bit, but provides insurance against errors due to
' SecureCRT and the script running asynchronously.
crt.Screen.Synchronous = true
' Start tailing a file...
crt.Screen.Send "tail tailfile.txt" & vbcr
' Example #1: Uses WaitForString to look for just the text
' we care about. Once the text is found, the
' line on which the text was located is captured
' and a piece of information is parsed using the
' Split() builtin VBScript method.
CaptureJustTheLinesWeCareAbout
' Example #2: Uses WaitForString to detect when every new line
' arrives from the remote. Each line of text is
' captured, and the Instr() builtin VBScript
' function is used to detect the presence of the
' specific text we care about. Iff it is present,
' the Split() builtin VBScript method is used to
' parse out the relevant piece of information.
'
' The benefit of this method over
' CaptureJustTheLinesWeCareAbout is that we
' can retrieve information from the line if
' the text we care about comes prior to the
' relevant piece of information that we would
' like to display as part of our notification.
'
' To enable this example, comment out the statement
' on line 29 and uncomment the line below:
' CaptureAllLinesAndSearchForTextWeCareAbout
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub CaptureJustTheLinesWeCareAbout()
MsgBox "Capturing just the lines we care about"
do
' Look for specific output
dim result
result = crt.Screen.WaitForStrings("changed state to up","changed state to down","%LINK-5-CHANGED","Duplicate address")
' Once specific output is found, capture the line
' of text on which the "changed to state down" string
' was located.
szCurrentLine = crt.Screen.Get(crt.Screen.CurrentRow, _
0, _
crt.Screen.CurrentRow, _
crt.Screen.Columns)
' Trim off any leading or training spaces
szCurrentLine = Trim(szCurrentLine)
' Use the Split() method (builtin VBScript method)
' to get at the component we care about (deviceID)
vElements = Split(szCurrentLine, " ")
for each x in vElements
'document.write(x & "<br />")
next
'MsgBox "Device """ & vElements(3) & """ just went down."
g_szLogFile = GetMyDocumentsFolder & "\Command#__NUM___Results.txt"
Set objTab = crt.GetScriptTab
select case result
case 1
'handle "changed state to up"
LogOutputOfSpecificCommandUseReadString
case 2
'handle "changed state to down"
LogOutputOfSpecificCommandUseReadString2
case 3
'handle "%LINK-5-CHANGED"
LogOutputOfSpecificCommandUseReadString3
end select
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & """ just went down."
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & "is " vElements(6)"
Loop
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub LogOutputOfSpecificCommandUseReadString()
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(g_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array g_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array g_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub LogOutputOfSpecificCommandUseReadString2()
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(h_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array h_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array h_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
Function GetMyDocumentsFolder()
Dim myShell
Set myShell = CreateObject("WScript.Shell")
GetMyDocumentsFolder = myShell.SpecialFolders("MyDocuments")
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub LogOutputOfSpecificCommandUseReadString3()
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(I_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array I_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array I_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
Function GetMyDocumentsFolder()
Dim myShell
Set myShell = CreateObject("WScript.Shell")
GetMyDocumentsFolder = myShell.SpecialFolders("MyDocuments")
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function NN(nNumber, nDesiredDigits)
' Normalizes a single digit number to have nDesiredDigits 0s in front of it
Dim nIndex, nOffbyDigits, szResult
nOffbyDigits = nDesiredDigits - len(nNumber)
szResult = nNumber
For nIndex = 1 to nOffByDigits
szResult = "0" & szResult
Next
NN = szResult
End Function
yes of course.
it would be better to name the function a meanningful name:
for changed state to up:
LogOutputOfSpecificCommand ChangedSta teToUp
and so on.
it would be better to name the function a meanningful name:
for changed state to up:
LogOutputOfSpecificCommand
and so on.
can u be more specific, what didn't work?
ASKER
Hi Sedgwick,
I changed the following lines:
and I created the following:
I changed the following lines:
select case result
case 1
'handle "changed state to up"
LogOutputOfSpecificCommandUseReadString
case 2
'handle "changed state to down"
LogOutputOfSpecificCommandUseReadString2
case 3
'handle "Duplicate address"
LogOutputOfSpecificCommandUseReadString3
end select
and I created the following:
Sub LogOutputOfSpecificCommandUseReadString3()
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(I_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array I_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array I_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
ASKER
So Sedgwick, when the text Duplicate address appears,
the following should be run:
The full code is as follows:
the following should be run:
Dim I_vCommands(100)
I_vCommands(0) = "term len 0"
I_vCommands(1) = "show ip traffic"
I_vCommands(2) = "show ip pim"
The full code is as follows:
# $language = "VBScript"
# $interface = "1.0"
' ASSUMPTION: file being 'tailed' contains information
' similar to:
' Jan 5 18:26:13 device01 9927: Jan 5 18:26:12: %LINK-3-UPDOWN: Interface POS5/2, changed state to down
' Jan 5 18:26:47 device02 6332: Jan 5 18:26:46.243: %LINK-3-UPDOWN: Interface GigabitEthernet3/1, changed state to down
' Jan 5 18:28:40 device01 9937: Jan 5 18:28:39: %LINK-3-UPDOWN: Interface POS5/2, changed state to down
Dim g_fso, g_shell
Set g_fso = CreateObject("Scripting.FileSystemObject")
Set g_shell = CreateObject("WScript.Shell")
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Dim g_szLogFile, g_szFirstLogFilePath, objTab
g_szLogFile = GetMyDocumentsFolder & "\Command#__NUM___Results.txt"
Set objTab = crt.GetScriptTab
Dim g_vCommands(100)
g_vCommands(0) = "show ip int brief"
g_vCommands(1) = "show cdp neighbor"
' .
' .
' .
Dim h_vCommands(100)
h_vCommands(0) = "term len 0"
h_vCommands(1) = "show run"
h_vCommands(2) = "show ip bgp"
' .
' .
' .
Dim I_vCommands(100)
I_vCommands(0) = "term len 0"
I_vCommands(1) = "show ip traffic"
I_vCommands(2) = "show ip pim"
' .
' .
' .
Sub Main()
' Make sure that we are running in Synchronous mode so
' that when WaitForStrings() finds something, we can
' capture the current line without risk of it already
' having flown by on the screen. This slows things down
' a bit, but provides insurance against errors due to
' SecureCRT and the script running asynchronously.
crt.Screen.Synchronous = true
' Start tailing a file...
crt.Screen.Send "tail tailfile.txt" & vbcr
' Example #1: Uses WaitForString to look for just the text
' we care about. Once the text is found, the
' line on which the text was located is captured
' and a piece of information is parsed using the
' Split() builtin VBScript method.
CaptureJustTheLinesWeCareAbout
' Example #2: Uses WaitForString to detect when every new line
' arrives from the remote. Each line of text is
' captured, and the Instr() builtin VBScript
' function is used to detect the presence of the
' specific text we care about. Iff it is present,
' the Split() builtin VBScript method is used to
' parse out the relevant piece of information.
'
' The benefit of this method over
' CaptureJustTheLinesWeCareAbout is that we
' can retrieve information from the line if
' the text we care about comes prior to the
' relevant piece of information that we would
' like to display as part of our notification.
'
' To enable this example, comment out the statement
' on line 29 and uncomment the line below:
' CaptureAllLinesAndSearchForTextWeCareAbout
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub CaptureJustTheLinesWeCareAbout()
MsgBox "Capturing just the lines we care about"
do
' Look for specific output
dim result
result = crt.Screen.WaitForStrings("changed state to up","changed state to down","%LINK-5-CHANGED","Duplicate address")
' Once specific output is found, capture the line
' of text on which the "changed to state down" string
' was located.
szCurrentLine = crt.Screen.Get(crt.Screen.CurrentRow, _
0, _
crt.Screen.CurrentRow, _
crt.Screen.Columns)
' Trim off any leading or training spaces
szCurrentLine = Trim(szCurrentLine)
' Use the Split() method (builtin VBScript method)
' to get at the component we care about (deviceID)
vElements = Split(szCurrentLine, " ")
for each x in vElements
'document.write(x & "<br />")
next
'MsgBox "Device """ & vElements(3) & """ just went down."
g_szLogFile = GetMyDocumentsFolder & "\Command#__NUM___Results.txt"
Set objTab = crt.GetScriptTab
select case result
case 1
'handle "changed state to up"
LogOutputOfSpecificCommandUseReadString
case 2
'handle "changed state to down"
LogOutputOfSpecificCommandUseReadString2
case 3
'handle "Duplicate address"
LogOutputOfSpecificCommandUseReadString3
end select
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & """ just went down."
'MsgBox "Device """ & vElements(0) & vElements(1) & vElements(2) & vElements(3) & "is " vElements(6)"
Loop
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub LogOutputOfSpecificCommandUseReadString()
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(g_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array g_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array g_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub LogOutputOfSpecificCommandUseReadString2()
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(h_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array h_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array h_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Sub LogOutputOfSpecificCommandUseReadString3()
' Instruct WaitForString and ReadString to ignore escape sequences when
' detecting and capturing data received from the remote (this doesn't
' affect the way the data is displayed to the screen, only how it is handled
' by the WaitForString, WaitForStrings, and ReadString methods associated
' with the Screen object.
objTab.Screen.IgnoreEscape = True
objTab.Screen.Synchronous = True
If Not objTab.Session.Connected then
crt.Dialog.MessageBox _
"Not Connected. Please connect before running this script."
exit sub
end if
Dim szCommand, szPrompt, nRow, szLogFileName, nIndex
' If this script is run as a login script, there will likely be data
' arriving from the remote system. This is one way of detecting when it's
' safe to start sending data. If this script isn't being run as a login
' script, then the worst it will do is seemingly pause for one second
' before determining what the prompt is.
' If you plan on supplying login information by waiting for username and
' password prompts within this script, do so right before this do..loop.
Do
bCursorMoved = objTab.Screen.WaitForCursor(1)
Loop until bCursorMoved = False
' Once the cursor has stopped moving for about a second, we'll
' assume it's safe to start interacting with the remote system.
' Get the shell prompt so that we can know what to look for when
' determining if the command is completed. Won't work if the prompt
' is dynamic (e.g. changes according to current working folder, etc)
nRow = objTab.Screen.CurrentRow
szPrompt = objTab.screen.Get(nRow, _
0, _
nRow, _
objTab.Screen.CurrentColumn - 1)
szPrompt = Trim(szPrompt)
Dim szLogFile
nIndex = 0
Do
szCommand = Trim(I_vCommands(nIndex))
' If the command is empty, then we should be done issuing commands
' (there's nothing else in our command array I_vCommands)
if szCommand = "" then Exit Do
' Set up the log file for this specific command
szLogFile = Replace(g_szLogFile, "__NUM__", NN(nIndex + 1, 2))
' Store the path for our first log file for later use (see end of this
' function...
if g_szFirstLogFilePath = "" then g_szFirstLogFilePath = szLogFile
' Send the command text to the remote
objTab.Screen.Send szCommand & vbcr
' Wait for the command to be echo'd back to us.
objTab.Screen.WaitForString vbcr, 1
objTab.Screen.WaitForString vblf, 1
Dim szResult
' Use the ReadString() method to get the text displayed while the
' command was runnning. Note that the ReadString usage shown below
' is not documented properly in SecureCRT help files included in
' SecureCRT versions prior to 6.0 Official. Note also that the
' ReadString() method captures escape sequences sent from the remote
' machine as well as displayed text. As mentioned earlier in comments
' above, if you want to suppress escape sequences from being captured,
' set the Screen.IgnoreEscape property = True.
szResult = objTab.Screen.ReadString(szPrompt)
Dim objFile
Set objFile = g_fso.OpenTextFile(szLogFile, ForWriting, True)
' If you don't want the command logged along with the results, comment
' out the very next line
objFile.WriteLine "Results of command: " & szCommand
' Write out the results of the command to our log file
objFile.WriteLine szResult
' Close the log file
objFile.Close
' Move on to the next command in our command array I_vCommands
nIndex = nIndex + 1
Loop
' Once we're complete, let's bring up Windows Explorer with the first of
' the log files selected.
g_shell.Run "explorer /e,/select,""" & g_szFirstLogFilePath & """"
End Sub
Function GetMyDocumentsFolder()
Dim myShell
Set myShell = CreateObject("WScript.Shell")
GetMyDocumentsFolder = myShell.SpecialFolders("MyDocuments")
End Function
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Function NN(nNumber, nDesiredDigits)
' Normalizes a single digit number to have nDesiredDigits 0s in front of it
Dim nIndex, nOffbyDigits, szResult
nOffbyDigits = nDesiredDigits - len(nNumber)
szResult = nNumber
For nIndex = 1 to nOffByDigits
szResult = "0" & szResult
Next
NN = szResult
End Function
ASKER
Hi Sedgwick,
I think I can take care of it from here.....
You've been brilliant.
What country are you in?
I think I can take care of it from here.....
You've been brilliant.
What country are you in?
Israel ;-)
ASKER
Wow!
If ever you come to London, or I go to Israel, I'll buy you a drink :-)
If ever you come to London, or I go to Israel, I'll buy you a drink :-)
U got it.
Cheers mate
Cheers mate
Dont forget to close the question, good luck mate.
ASKER
I would like to take a moment to express my eternal gratitude to this Expert. Not just for his impeccable skills but for his dogged determination to see the problem through to the end.
It is Experts like Sedgwick that will make customers remain customers.
I wish I was in a position to award Sedgwick more than 500 points as he deserves every point awarded to him.
As long as there are experts like Sedgwick working for EE I will always pay my subscription fee.
Thank you very much Sedgwick
Cheers
Carlton
It is Experts like Sedgwick that will make customers remain customers.
I wish I was in a position to award Sedgwick more than 500 points as he deserves every point awarded to him.
As long as there are experts like Sedgwick working for EE I will always pay my subscription fee.
Thank you very much Sedgwick
Cheers
Carlton
thanks again for your kind words.