automated script of defrag question

  • Thread starter Thread starter Nathan H
  • Start date Start date
N

Nathan H

Hi all

I'm trying to create a batch script on Windows Server 2003 (commands should
be relevent to 2000 also) that:

- cleans up any temp files
- analyzes a partition and records the info to a log file
- checks the created log file to see whether defrag needs to take place

The 3rd point is the problem I have.

I've managed to output defrag's analyze report but I'm having trouble
finding
a command that allows me to check that log file for the word "should" and
then
base an outcome if it finds it i.e.

output.log -----> "Should" ---> Yes ----> Run defrag
----> No -----> Finish

Hope that makes sense.

Any one have any ideas?

I've tried using FINDSTR but all I can get is it repeating the line
"should" was in and I cant think how to include it in a If & GOTO
routine.

Many Thanks,
 
Nathan H said:
Hi Nathan.
I've tried using FINDSTR but all I can get is it repeating the line
"should" was in and I cant think how to include it in a If & GOTO
routine.

find /I "should" <output.log||echo No defrag &goto :nodefrag
echo do defrag

a second way

set "Cnt=0"
for /F %%A ('find /I /C "should" ^<output.log') do set Cnt=%%A
if %Cnt% GEQ 1 (
echo do defrag
) else (
echo no defrag
)

HTH
 
¦Find's exit codes
¦The following list shows each exit code and a brief description of its
¦meaning:
¦
¦0
¦ The search was completed successfully and at least one match was found.
¦
¦1
¦ The search was completed successfully, but no matches were found.
¦
¦2
¦ The search was not completed successfully. In this case, an error
¦ occurred during the search, and FIND cannot report whether any matches
¦ were found.
¦
¦You can use the ERRORLEVEL parameter on the <If> command line in a batch
¦program to process exit codes returned by FIND.
 
Hi David

¦Find's exit codes

That was just what I was after....

:)

Is there a good way of finding EXIT codes - I've been to a few well known
websites
regarding batch files and they have some of the EXIT codes, but is there a
really good
source that you know of?

Many regards to you (and Mattias) for your suggestions & help,
Nathan H.
 
Dos 6.22 help file (as XP's dos commands are Dos 5), XP's help file (for NT commands). These are the only places I know of them being listed.
 
Back
Top