-----Original Message-----
From: David Cook
Sent: Wednesday, 20 August 2003 8:53 AM
To: [EMAIL PROTECTED]
Subject: Check for string in file RE: [SA-list] SA List Text fileI'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
:Start
$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
COPY "X:\dont_remove_this_file.log" "$log" /h
SETFILEATTR("$log",128)
GOTO "Start"
: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
Title: Message
For
all who asked about this I've imporoved the sscript slightly (for my usage
anyway) by including a couple of lines to create the file if it doesn't exist,
note that theres no ENDIF, thats because (1)I'm not a script guru and (2)For me
it works better as below.
Dave
C
- Check for string in file RE: [SA-list] SA List Text file David Cook
- David Cook
