Title: Check for string in file RE: SA List Text file

I've had quote a few responses wanting to see this script, I warn you though I'm not a script guru by any stretch so if you can think of any mods let the list know! Caveats inc the requirement of Kix and qgrep available in the W2K resource kit.

Regards,

Dave Cook

;String serach in file check for Servers alive
;Requires Servers Alive qgrep and kix2001 to function
;
;History at top please
;
;Author         Date            Change
;DCook          270503          Created initial script
;
FUNCTION pipe($command)
 DIM $error, $tempfile
 DIM $FSO, $oFile
 $tempfile = "%temp%\pipe.tmp"
 IF Exist($tempfile)  DEL $tempfile  ENDIF
 IF @inwin = 2 ; win9x
   SHELL '%comspec% /c '+$command+' >"'+$tempfile+'"'
 ELSE ; winnt
   SHELL '%comspec% /c '+$command+' >"'+$tempfile+'" 2>nul'
 ENDIF
 $error = @Error
 ;
 $pipe = ""
 $FSO = CreateObject("Scripting.FileSystemObject")
 IF @Error <> 0  EXIT @Error  ENDIF
 $oFile = $FSO.OpenTextFile($tempfile,1,0)
 IF @Error = 0
   $pipe = SPLIT($oFile.ReadAll,@CRLF)
   $oFile = 0
   $FSO = 0
 ENDIF
 ;
 DEL $tempfile
 EXIT $error
ENDFUNCTION
;The following line uses the built in kix date macro and then rearranges the date to form the name of the log file
$x=substr(@DATE,LEN(@DATE)-9,4)+substr(@DATE,LEN(@DATE)-4,2)+substr(@DATE,LEN(@DATE)-1,2)
;In our case the file exists on a mapped X: drive using a log extension with the name derived above
$log="x:\"+$x+".log"
$ErrLev=1
IF EXIST ($log)
GOTO "Good"
ELSE
GOTO "Nilfile"
:Good
$result=pipe('qgrep -l -y -e "insert here text you want to search for" $log')
For each $line In $result
IF $line=$log
EXIT $ErrLev
ELSE
GOTO "Nilerror"
ENDIF
next
:Nilerror
exit
:Nilfile
EXIT $ErrLev

Reply via email to