Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

 
 
Thread Tools Rate Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 03-15-2012, 11:50 AM
mikit mikit is offline
Registered User
 
Join Date: Mar 2012
Posts: 38
problem log file

Hi there,

I got a little problem. I have a script that logs in to device and gets some info from it. Everything is logged into a file. Problem is when script hits the device to which it cannot log in.

Here is the script:

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

Sub main

Dim ip, line, cnxString, folder, index, Path, fso, fil, objFSO, objLogFile, strCurrentLine

'read file with IP and set path
Const DEVICE_FILE_PATH = "c:\direcotry\ips.txt"
Path = "c:\direcotry\"
Set fso = CreateObject("Scripting.FileSystemObject")
Set fil = fso.OpenTextFile(DEVICE_FILE_PATH)
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Telneting using IPs from txt file
While Not fil.AtEndOfStream
line = fil.ReadLine
ip = Split(line, ";")(0)
cnxnString = "/TELNET " & ip & " 23"

crt.Screen.Synchronous = True

crt.session.Log(false)

'Connect
crt.Session.Connect cnxnString

'create and open log file
Set lfile = fso.CreateTextFile(Path & "log.txt")
Set lfile = nothing
Set objFolder = nothing
Set lfile = fso.OpenTextFile(Path & "log.txt", 8, True)

'if any error during connection, will continue with next IP
On Error Resume Next

'get required info and check if it is OK
crt.Screen.WaitForString ("sername:")
crt.Screen.Send "user" & vbCr
index = Crt.Screen.WaitForString("CODE:")
index = crt.Screen.WaitForString("#")
timeout = 3
index = crt.Screen.WaitForString("<<<", timeout)
index = crt.Screen.WaitForString("#", timeout)


'read hostname
hostname = crt.Screen.Get(crt.Screen.CurrentRow, 1, crt.Screen.CurrentRow, 50)
hostname = Left(hostname, Instr(1, hostname, ">", 1) - 1)

lfile.WriteLine(hostname)

'write actual date and time
crt.Screen.Send "sh clock" + vbCr
crt.Screen.WaitForString "#"
file = crt.Screen.Get(crt.Screen.CurrentRow-1, 1,crt.Screen.CurrentRow-1, 150 )
lfile.Write (file) & vbCrLf

'will check if required string is present
crt.Screen.Send "sh run | i no ip source" + vbCr
crt.Screen.WaitForString "#"
lfile.Write ("sh run | i no ip source") & vbCrLf
file = crt.Screen.Get(crt.Screen.CurrentRow-1, 1,crt.Screen.CurrentRow-1, 150 )
If Instr(1, file, "sh run", 1) <> 0 Then
lfile.Write "..." & vbCrLf
Else lfile.Write (file) & vbCrLf
End if
If Instr(1, file, "no ip source-route", 1) <> 0 Then
lfile.Write "NISR OK" & vbCrLf
ElseIf Instr(1, file, "no ip source route", 1) <> 0 Then
Else lfile.Write "NISR FALSE" & vbCrLf
End If

crt.Sleep 1000

crt.Screen.Send "sh run | i ervice password" + vbCr
crt.Screen.WaitForString "#"
lfile.Write ("sh run | i ervice password") & vbCrLf
file = crt.Screen.Get(crt.Screen.CurrentRow-1, 1,crt.Screen.CurrentRow-1, 150 )
If Instr(1, file, "sh run", 1) <> 0 Then
lfile.Write "..." & vbCrLf
Else lfile.Write (file) & vbCrLf
End if
If Instr(1, file, "service password", 1) <> 0 Then
lfile.Write "SPE OK" & vbCrLf
Else lfile.Write "SPE FALSE" & vbCrLf
End If

crt.Sleep 1000

'add line at the end of each check
lfile.WriteLine("-------------------------") & vbCrLf

'Close log file
'lfile.Close

crt.Screen.Synchronous = true

'Disconnect
crt.Session.Disconnect
Wend

End Sub


And here is the extract from log:

devicename1#
16:18:28.155 UTC Thu Mar 15 2012
sh run | i no ip source
no ip source-route
NISR OK
sh run | i ervice password
service password-encryption
SPE OK
sh run | i ogging IP
logging IP
LOG OK
-------------------------

Basically it logs in and checks if certain commands are present in configuration.

Problem occurs when script hits the device to which it cannot log in (password is not working). What happens is, that each time it hits the nonaccessible device it adds lines to the log which shouldn't be added. Then the log looks like this:

devicename1#
16:18:28.155 UTC Thu Mar 15 2012
sh run | i no ip source
no ip source-route
NISR OK
sh run | i ervice password
service password-encryption
SPE OK
sh run | i ogging IP
logging IP
LOG OK
-------------------------
devicename1#
logging IP
sh run | i no ip source
logging IP
NISR FALSE
sh run | i ervice password
logging IP
SPE FALSE
sh run | i ogging 3.10.203.48
logging IP
LOG OK
-------------------------

I am not sure what is going on, but it looks like that something got stucked in a buffer.

Any ideas where can be a problem?
Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -6. The time now is 10:32 PM.