Jump to content
Sign in to follow this  
scubasteve1281

best way to open a file read the contents and create an event based on contents

Recommended Posts

scubasteve1281

I'm building a script that will be compiled and run as a service the once a day that will execute the program. the program creates a text file that is based on the date and saves it. What would be the best to open this the txt file parse the information for key words then if those key words are found it will right an event to the event log. I have figured out how to open a txt file and and have it search for a word. I have also figured out how to write to a the event logs. The problem I'm having what is the best/easiest way to find and load the .txt file based on the latest date. There will be multiple files there and I need it to pull the latest one.

Should I load this into an array... or another way is loading the out put into an array while the program is running then after it is done parsing have it save the file.

Here is the an example of the code I have so far its pretty crude

;event log

$SystemEventError='eventcreate /T Error /ID 1000 /L APPLICATION /SO "File Integrity Checker" /D "File Integrity Checker Failed to Execute Check the C:\Program"'

$SystemEventSuccess='eventcreate /T Information /ID 1001 /L APPLICATION /SO "File Integrity Checker" /D "File Integrity Checker Sucessfully verifed the Hashfile located at "C:\Program Files\FIC\Baseline\Baseline.txt"'

;loading and reading files

$TextFileName = "C:\Program Files\FIC\logs\;unique date.txt"

;$FindText = "fail"

;Creates the directory stucture

If Not FileExists("C:\Program Files\FIC") Then DirCreate("C:\Program Files\FIC")

If Not FileExists("C:\Program Files\FIC\Logs") Then DirCreate("C:\Program Files\FIC\Logs")

If Not FileExists("C:\Program Files\FIC\Baseline") Then DirCreate("C:\Program Files\FIC\Baseline")

;installs the required Files

If Not FileExists("C:\Program Files\FIC\FIC.exe") Then FileInstall ("C:\Users\sfrey.IA\Desktop\FIC\FIC.exe", "C:\Program Files\FIC\FIC.exe")

If Not FileExists("C:\Program Files\FIC\FICcheck.bat") Then FileInstall ("C:\Users\sfrey.IA\Desktop\FIC\FICcheck.bat", "C:\Program Files\FIC\FICcheck.bat")

;exucutes the file check and the scan

If FileExists("C:\Program Files\FIC\Baseline\Baseline.txt") Then RunWait ("C:\Program Files\FIC\FICcheck.bat" ,"" ,"@SW_HIDE")

If Not FileExists("C:\Program Files\FIC\Baseline\Baseline.txt") Then RunWait("C:\Program Files\FIC\FIC.exe -r -sha256 -otf ""C:\Program Files\FIC\Baseline\Baseline.txt"" -d C:\ *.bat *.com *.dll *.exe" ,"" ,"@SW_HIDE")

;loading and reading files

$TextFileName = "C:\Program Files\FIC\logs\;unique date.txt"

$FileContents = FileRead($TextFileName)

If $FindText = "fail" then Run(@ComSpec & " /c " & $SystemEventError, "")

;the contents of the .bat file is

"C:\Program Files\FIC\FIC.exe" -cv "C:\Program Files\FIC\Baseline\Baseline.txt" -d c:\ > "C:\Program Files\FIC\Logs\%date:~10,4%%date:~4,2%%date:~7,2%.txt"

and the out put txt file is named like this: 20091008.txt

help would be much appreciated

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.