Solved

read contents of file and return boolean

Posted on 2007-04-09
11
182 Views
Last Modified: 2013-11-26
i  have a log file that is created with the following syntax

{
-name "Adidas Blend"
-start -cron 30 9 * * 7
-action -log "d:\Scheduler.log" "ADS Blend Task Start Time - %c%"
-action -pwd CUR_DIR
-action -print "Current directory is %CUR_DIR%"
-action -cd "D:\DMS_Live\ADS_Blend"
-action -pwd CUR_DIR
-action -print "After CD, current directory is %CUR_DIR%"
-action -spawn "ADS_Blend.exe"
-action -log "d:\Scheduler.log" "ADS Blend Task End Time - %c%"
}

Each day this file adds a new line.  I need to be able to right some vb.net code that opens the file and checks to see that the two lines are created each day.  maybe it wiill return a boolean value.
0
Comment
Question by:Robb Hill
  • 6
  • 5
11 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18878082
A boolean value with respect to what?...
0
 
LVL 11

Author Comment

by:Robb Hill
ID: 18878139
the program should open the file...verify the last two lines are there ....if they are both there..then return true..else return false.  These two lines are appended to the file everytime the job runs.  Im trying to create an alert when this file is missing these two lines on a given day.

-action -log "d:\Scheduler.log" "ADS Blend Task Start Time - %c%"
-action -log "d:\Scheduler.log" "ADS Blend Task End Time - %c%"

0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18878261
Ok...do those two lines have anything to indicate WHEN they were added?

Does "%c%" get replaced by something in the actual file or is that literally what is there?

Or do I have it all wrong?

Is the file recreated each day with the stuff you originally posted and then the two lines from your last post are added at some point?
0
 
LVL 11

Author Comment

by:Robb Hill
ID: 18878336
each day a process runs.  This scheduler program called wincron runs the exe files....
This program appends to a log file.  The %c% will put a date at the end of the log.

And yes, the file created each day is an append of the original file.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18878810
"The %c% will put a date at the end of the log."

In what format will the date be so we can check against the current date?
0
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
LVL 11

Author Comment

by:Robb Hill
ID: 18881804
12/21/03 11:37:54
0
 
LVL 11

Author Comment

by:Robb Hill
ID: 18890555
This is what I have so far.  I wish there was a way so that my date test was always the current Saturday of the month.

'Open a file for reading
        Dim FILENAME As String = "c:/Scheduler.log"
        Dim looptest As Boolean = True

        'Get a StreamReader class that can be used to read the file
        Dim objStreamReader As StreamReader
        objStreamReader = File.OpenText(FILENAME)

        'Now, read the entire file into a string
        Dim contents As String = objStreamReader.ReadToEnd()

        Dim a() As String = Split(contents, vbCrLf)
        Dim now As DateTime = DateTime.Now.ToShortDateString
        For i As Integer = 0 To a.Length - 1

            Dim strArray() As String = a(i).Split("-")
            strArray(1) = LTrim(strArray(1))
            Dim strDate() As String = strArray(1).Split(" ")

            If strDate(0) = now Then
                looptest = True
                Exit Sub
            Else
                looptest = False
            End If
        Next
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 18891917
How about something like?...

(This is the .Net Framework 2.0 TA so I assume you are using VB.Net 2005)

    Private Function FileUpdated() As Boolean
        Dim fileName As String = "c:\Scheduler.log"
        Dim contents As String = My.Computer.FileSystem.ReadAllText(fileName)
        Dim lines() As String = contents.Replace(vbCrLf, vbCr).TrimEnd(vbCr).Split(vbCr)
        Dim curSaturday As Date = DateTime.Today.AddDays(DayOfWeek.Saturday - DateTime.Today.DayOfWeek)
        Dim lastLine As String = lines(lines.GetUpperBound(0))
        If lastLine.IndexOf("ADS Blend Task End Time") <> -1 Then
            Dim lastDash As Integer = lastLine.LastIndexOf("-")
            Dim strDateTime As String = lastLine.Substring(lastDash + 1).Trim
            Dim lastDateTime As DateTime
            If DateTime.TryParse(strDateTime, lastDateTime) Then
                Dim lastDate As Date = lastDateTime.Date
                If lastDate.CompareTo(curSaturday) = 0 Then
                    Return True
                End If
            End If
        End If
        Return False
    End Function
0
 
LVL 11

Author Comment

by:Robb Hill
ID: 18892111
I really like your use of my...im still trying to learn all the advantages of some of the new 2.0 stuff.
Do you have any recomendations.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 18892133
Don't have any recommendations sorry...I'm still learning them myself!  =)
0
 
LVL 11

Author Comment

by:Robb Hill
ID: 18892151
Well thanks again.  
0

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now