antmar904

Parse through log file

5 posts in this topic

#1 ·  Posted

Hi,

I ran a remote program on 180 computers and logged the output to a log file with paexec.  I'm trying to parse through the log file to see which computers launched the program successfully and record the computer name but I'm not sure how to go about it. 

I can successfully open the log file, read it but not sure how to start separating the data.

I've attached the log file, basically every computer entry in the log file for a new computer starts with "Connecting to <computername>..." I was thinking about using that as the start and stop point for retrieving the end results.  Anything with a "returned 0" is a success, everything is a fail.

Any help is much appreciated.

testlogfile.txt

Share this post


Link to post
Share on other sites



#3 ·  Posted

This example appears to work on your Test log file.

;#include <Array.au3>
#include <File.au3>

Local $sFileName = "testlogfile.txt"
$a = StringRegExp(FileRead($sFileName), "Connecting to ([^\.]+).*\v+Starting PAExec.+\v+Copying.+\v+.+returned 0", 3)

;_ArrayDisplay($a)
_FileWriteFromArray("SuccessComputers.txt", $a) ; Record results
ShellExecute("SuccessComputers.txt")

 

Share this post


Link to post
Share on other sites

#4 ·  Posted

also, avoiding regex

#include<array.au3>

$aSplit = stringsplit(fileread("testlogfile.txt") , @LF , 2)
$aFound = _ArrayFindAll($aSplit , "returned 0" , 0 ,0 ,0 ,1)

for $i = 0 to ubound($aFound) - 1
    $aFound[$i] = stringtrimleft(stringtrimright($aSplit[$aFound[$i] -4] , 4) , 14)
Next

_ArrayDisplay($aFound)

 


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites

#5 ·  Posted

Thank you all. 

I tried a couple of ways myself with no luck.  @Malkey and @iamtheky both of your scripts work well.  Now it's time to learn on what they are doing.

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

  • Similar Content

    • wimhek
      By wimhek
      Is it possible , and how can I read and write txt files from Icloud (apple service) ?
      Let me try to explain my application.
      On my Ipad and Iphone I create txt files. On my windows computer it is possible to read and modify these files manually, by logging in on www.icloud.com.
      What I want to make is an auto-it script who reads the txt file and create an new txt file on www.icloud.com,  so I can acces these on my ipad and/or phone.
       
      Thank you.
    • LWC
      By LWC
      I've made a program that relies on IniReadSectionNames. It reads (~3K) Autorun.inf files in the working folder and creates a GUI based on their contents.
      I made sure to revert to a default GUI upon @error.
      But someone (with Windows XP SP3 32-bit) reported to me he always gets the default menu.
      I sent him a FileRead command instead and it works! So seemingly there's no access problem to AutoRun.inf.
      In the following demo code, I always hit success, but he always ends up with semi-success:
      Local $hIniLocation = "Autorun.inf" Local $aSections = IniReadSectionNames($hIniLocation) If @error Then $aSections = FileRead($hIniLocation) if @error then msgbox(48, "Double error", "Alternative access failed too due to:" & @crlf & @error & @crlf & @extended) else msgbox(0, "Semi-success", "IniReadSectionNames failed, but alternativaly this file contains:" & @crlf & @crlf & $aSections) endif else msgbox(0, "Success", "IniReadSectionNames worked!") endif Why is that? Is there something further to check with him?
      Autorun.inf
    • souldjer777
      By souldjer777
      Howdy Everyone!
      I've been scouring the forum for something that works... and no dice yet... hoping to stop the frustration - hope someone in the forum knows what to do.
      Basically, I've saved .msg files out of MS Outlook and want to scan each on for email addresses but all I get with fileopen and fileread are symbols... ran through every iteration.
      I've seen people do some soft of binary extract and binarytostring but I haven't gotten that to work either... not sure what's going on.
      Neither of these have worked for me... yes I know they are old and FileOpen has changed... but like I said I tried everything that I know of.
      Please help
       
      $sFile = "C:\temp\messages\Test.msg" $hFile = FileOpen($sFile, 16) ; 16 = binary $binData = FileRead($hFile, 1024) ; read first 1KB FileClose($hFile) ConsoleWrite("Debug: First 1KB = " & $binData & @LF) or...
      $sFile = "C:\temp\messages\Test.msg" $hFile = FileOpen($sFile, 16) $binData = FileRead($hFile, 20480) FileClose($hFile) $startdef=StringTrimLeft(Binary('thetextIamlookingfor'), 20) $enddef=StringTrimLeft(Binary('moretextIamlookingfor'), 20) $binData=StringTrimLeft($binData, StringInStr($binData, $startdef)+StringLen($startdef)-1) $binData=StringLeft($binData, StringInStr($binData, $enddef)-1) ConsoleWrite(BinaryToString('0x'&$binData) & @LF) Thanks!
    • david1337
      By david1337
      Hi guys
      I hope you can help me out
      I have a script that checks for the current user's loginname in different txt files.
      If the current user's loginname is found in one of the txt files, the script reacts based on that.
      The text files look something like this:
      dle
      oej
      zaq
      oei
       
      (different usernames)
       
      This is an example of the script:
      $username = @UserName ;pulls username that is logged in $Dir = "C:\Test\" Global $Custom[] = ["text01", "text02", "text03", "text04"] ;CHECK LISTS For $i = 0 To UBound($Custom) - 1 $CustomFile = FileOpen($Dir & $Custom[$i] & ".txt", 0) $Readtxt = FileRead($CustomFile) FileClose($CustomFile) If StringRegExp($Readtxt, $username) Then do this and that... EndIf Next It works perfectly if the user logs in as xxxx or XXXX (Both lower and upper case characters)
      So the FileRead function doesn't seem to be case sensitive.
      But if the user logs in as xxXx (mix of lower and upper case characters), then the username is not recognized in the txt file.
       
      Does anyone have a suggestion on how I can fix this?
      Thanks in advance!
      - David
       
    • souldjer777
      By souldjer777
      Good Morning All,
      I'm hoping someone here can work their AutoIT magic 
      I'm doing a pretty "simple" string search in a HUGE variable.
      But I'm doing the basics almost straight out of the Help File...

      ( sorry, I'm leaving out my main code for privacy reasons )
      Local $hFileOpen = FileOpen($sFilePath, $FO_READ) Local $sFileRead = FileRead($hFileOpen) Local $sEmailPosition01 = StringInStr ($sFileRead, $sEmailAddress ) Everything looks good with my troubleshooting
      I ran IsString against $sFileRead and $sEmailAddress and was okay: "The variable is a string"
      So then I ran StringLen($sFileRead) and got string length 68352786
      Yeah, I know... That's HUGE - But it worked with the older version of AutoIT (upgraded yesterday) v3.3.14.2
      Is there an "Excessive" variable I should set?!? lol. Should I search the string a different way maybe?
      I know the string is in there... but I'm getting a StringInStr @error : 0 @extended: 0
      Please help! Thank you all