Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
Old 09-30-2008, 11:02 AM
djudd djudd is offline
Registered User
 
Join Date: Sep 2008
Posts: 3
Need to skip the first line when reading back a text file

First a disclaimer...I'm using SecureCRT 3.4....yes I know it's 2008, but I've just always used it so please forgive me.

I'm cobbling together a VBS script to automate some route work, and part of it is starting a local text file, cat'ing a file on a unix server, stopping the file, logging into a device and spitting it back out from the local copy. Here's the relevant bit:
crt.Session.Log True
crt.Screen.Send "cat /home/djudd/tmp/" & router_name & "_4.txt" & vbCr
crt.Screen.WaitForString "$"
crt.Session.Log False

Then I'm just using the text book example for reading back a locally created text file:
Const ForReading = 1
Const ForWriting = 2

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

' Note: A runtime exception will be generated if 'input.txt' doesn't exist.
'
Set file = fso.OpenTextFile("c:\mysession.log", ForReading, False)

crt.Screen.Synchronous = True

Do While file.AtEndOfStream <> True

str = file.Readline
' Send the line with an appended CR
'
crt.Screen.Send str & Chr(13)
' Wait for my prompt before sending the next line
'
'crt.Screen.WaitForString "prompt$"
Loop

crt.Screen.Synchronous = False

So here's my question. The local text file created contains a grep command that I don't want spit back into the router config...any ideas on how to get it out? First I tried moving the session.log true statement until after the cat command, then I tried usin WSH to invoke a local copy of "egrep -v" but I suspect my ancient copy of SecureCRT caused that to error out....so right now I'm at a wall. I just need to skip the first line...but the file will vary in length so I dont know what line it will stop on.

Any ideas would help, thanks.
Reply With Quote
  #2  
Old 09-30-2008, 12:23 PM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hi Djudd,

Have you considered using the built in VBScript function of 'instr' to check to see if "grep" exits in the "str" variable?

The send of the string and the wait for the prompt could be placed in an if statement and only sent if the string does not contain "grep".

Would this be an option?
__________________
Thanks,

Teresa

Teresa Nygren
Reply With Quote
  #3  
Old 09-30-2008, 03:07 PM
djudd djudd is offline
Registered User
 
Join Date: Sep 2008
Posts: 3
So what your saying is the first line could be filtered by using that method as long as there was a unique string to catch it with.

Here's an example of the first line I want to not pass back:
djudd/12:05pm~$cat /home/djudd/tmp/r2.sfldmi_4.txt

So I could set it to say "hey, if instr =djudd, then don't send that file and just keep moving on your merry way"?

Any advice on how to try that? I've never really coded before so I"m kinda learning as I go
Reply With Quote
  #4  
Old 09-30-2008, 03:24 PM
tnygren's Avatar
tnygren tnygren is offline
Registered User
 
Join Date: May 2005
Posts: 1,408
Hi Djudd,

Here is an example of what it would look like:
Code:
If instr (str, "grep") = 0 then

    crt.Screen.Send str & Chr(13)
    ' Wait for my prompt before sending the next line
    '
    'crt.Screen.WaitForString "prompt$"

End If
This code will only execute the send if "grep" is NOT present in the string.

Does this help?
__________________
Thanks,

Teresa

Teresa Nygren
Reply With Quote
  #5  
Old 09-30-2008, 04:23 PM
djudd djudd is offline
Registered User
 
Join Date: Sep 2008
Posts: 3
That does help thank you for the direction on that, I ended up using it like this:

Do While file.AtEndOfStream <> True

str = file.Readline
' Send the line with an appended CR
If instr (str, "djudd") = 0 then
crt.Screen.Send str & Chr(13)
else
end if
' Wait for my prompt before sending the next line
'crt.Screen.WaitForString "prompt$"
Loop

So it removes the first line that contains the text djudd....of course it would remove any line number, but the point is it works Thanks again I really appreciate the help, it save me from having to do this 280 times by hand.
Dennis

Last edited by djudd; 09-30-2008 at 07:32 PM.
Reply With Quote
Reply


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

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

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

Forum Jump


All times are GMT -6. The time now is 04:19 PM.