Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 08/06/2017 in all areas

  1. The username exists in 'E72N7-007584.31672.01.gtlead.00197' and also in 'User authenticated: gtlead'. The latter is easier to get But if the statements line you wrote is not the only text in the .log files, then the regex must be fixed by adding "(?s)" . This assumes that there is one log file per user $content = "text" & @crlf & _ " (http-0.0.0.0:8543-2) E72N7-007584.31672.01.gtlead.00197 - 2017/07/26-14:56:35,709 UTC - #SecretServerName - User authenticated: gtlead " & @crlf & "end text" $user = StringRegExpReplace($content, '(?s).*User authenticated: (\S+).*', "$1") Msgbox(0,"", $content & @crlf & @crlf & "user is " & $user) So what does '$1' mean here? In a StringRegExpReplace , the pattern describes the whole string . The part to match is the group (between parenthesis) and "$1" is the backreference which contains the match The expression in the code above means : "replace the whole text by the part where one or more non-space characters which follow the literal 'User authenticated: ' string" Edit BUT, if there are several users mentioned in the same .log file then it should rather be like this #include <File.au3> #include <Array.au3> Global $sFolderPath = FileSelectFolder("Select Folder", @scriptdir,"") Global $aFileList = _FileListToArrayRec($sFolderPath, "*.log", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_SORT, $FLTAR_FULLPATH) ;_ArrayDisplay($aFileList) ; create global list of all usernames found Local $sUsersList For $i = 1 to $aFileList[0] $content = FileRead($aFileList[$i]) $aUsers = StringRegExp($content, 'User authenticated: (\S+)', 3) If not @error Then For $k = 0 to UBound($aUsers)-1 $sUsersList &= $aUsers[$k] & @crlf Next EndIf Next ;MsgBox(0, "", $sUsersList) $aList = StringSplit($sUsersList, @crlf, 3) ; create a 2D array Local $aListCount[UBound($aList)][2], $k = 0 For $i = 0 to UBound($aList)-1 ; count occurences of each user in the list $sUsersList = StringReplace($sUsersList, $aList[$i], "") $count = @extended ; skip if count already done for this user If $count = 0 Then ContinueLoop ; fill the 2D array with users and count $aListCount[$k][0] = $aList[$i] $aListCount[$k][1] = $count $k += 1 Next Redim $aListCount[$k][2] _ArrayDisplay($aListCount)
    1 point
  2. version: 1.0.0 Every type should now be supported with ease. "__defineMethod" is now deprecated "__unset" added "__lock" added Documentation will be above for most recent release, or on GitHub for older releases.
    1 point
  3. Hi Rota Here's an example of monitoring a file for open handles script opens a file with exclusive access and fails if file already open by another application. this code wont work with some programs and files that don't seem to keep an open file handle. e.g. open a text file with a text editor (TextPad) and _FileInUse() reports no open handles works fine with programs like Word and Excel etc. Example Opt('MustDeclareVars', 1) Local $file = "C:\ABC.XLS" Local $bFileOpen If Not FileExists($file) And ConsoleWrite("!FileExists error: " & $file & @crlf) Then Exit While 1 Sleep(10) $bFileOpen = _FileInUse($file, 1) If $bFileOpen = -1 And ConsoleWrite("!_FileInUse() error" & @crlf & '>Error code: ' & @error & @crlf) Then Exit ConsoleWrite('-FileInUse = ' & ($bFileOpen <> 0) & @crlf & '>Error code: ' & @error & @crlf) If Not $bFileOpen Then ConsoleWrite("! File: "& $file &" is not in use" & @CRLF) Exit EndIf WEnd ;from this post: ;Need help with copy verification ;http://www.autoitscript.com/forum/index.php?showtopic=53994 ;=============================================================================== ; ; Function Name: _FileInUse() ; Description: Checks if file is in use ; Syntax.........: _FileInUse($sFilename, $iAccess = 1) ; Parameter(s): $sFilename = File name ; Parameter(s): $iAccess = 0 = GENERIC_READ - other apps can have file open in readonly mode ; $iAccess = 1 = GENERIC_READ|GENERIC_WRITE - exclusive access to file, ; fails if file open in readonly mode by app ; Return Value(s): 1 - file in use (@error contains system error code) ; 0 - file not in use ; -1 dllcall error (@error contains dllcall error code) ; Author: Siao ; Modified rover - added some additional error handling, access mode ; Remarks _WinAPI_CreateFile() WinAPI.au3 ;=============================================================================== Func _FileInUse($sFilename, $iAccess = 0) Local $aRet, $hFile, $iError, $iDA Local Const $GENERIC_WRITE = 0x40000000 Local Const $GENERIC_READ = 0x80000000 Local Const $FILE_ATTRIBUTE_NORMAL = 0x80 Local Const $OPEN_EXISTING = 3 $iDA = $GENERIC_READ If BitAND($iAccess, 1) <> 0 Then $iDA = BitOR($GENERIC_READ, $GENERIC_WRITE) $aRet = DllCall("Kernel32.dll", "hwnd", "CreateFile", _ "str", $sFilename, _ ;lpFileName "dword", $iDA, _ ;dwDesiredAccess "dword", 0x00000000, _ ;dwShareMode = DO NOT SHARE "dword", 0x00000000, _ ;lpSecurityAttributes = NULL "dword", $OPEN_EXISTING, _ ;dwCreationDisposition = OPEN_EXISTING "dword", $FILE_ATTRIBUTE_NORMAL, _ ;dwFlagsAndAttributes = FILE_ATTRIBUTE_NORMAL "hwnd", 0) ;hTemplateFile = NULL $iError = @error If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, -1) $hFile = $aRet[0] If $hFile = -1 Then ;INVALID_HANDLE_VALUE = -1 $aRet = DllCall("Kernel32.dll", "int", "GetLastError") ;ERROR_SHARING_VIOLATION = 32 0x20 ;The process cannot access the file because it is being used by another process. If @error Or IsArray($aRet) = 0 Then Return SetError($iError, 0, 1) Return SetError($aRet[0], 0, 1) Else ;close file handle DllCall("Kernel32.dll", "int", "CloseHandle", "hwnd", $hFile) Return SetError(@error, 0, 0) EndIf EndFunc
    1 point
×
×
  • Create New...