VanDyke Software Forums

VanDyke Software Forums (https://forums.vandyke.com/index.php)
-   Scripting (https://forums.vandyke.com/forumdisplay.php?f=14)
-   -   Need to skip the first line when reading back a text file (https://forums.vandyke.com/showthread.php?t=3218)

djudd 09-30-2008 11:02 AM

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.

tnygren 09-30-2008 12:23 PM

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?

djudd 09-30-2008 03:07 PM

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:o

tnygren 09-30-2008 03:24 PM

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?

djudd 09-30-2008 04:23 PM

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 :D Thanks again I really appreciate the help, it save me from having to do this 280 times by hand.
Dennis


All times are GMT -6. The time now is 02:07 PM.