Jump to content
The mkiv Supra Owners Club

Help with Windows batch file


tbourner

Recommended Posts

I'm new to batch files and DOS, never done anything very complicated so I've read up a bit on IF and SET and tried to understand the syntax for FOR but couldn't!

 

So can someone have a look through this code and see if it can be made any better/smaller/simpler please?

 

@echo off
set /p DRIVES=Enter the number of drives (max 24):
set /p TEMP=Enter the current run temperature in degrees C:
Set /a DRIVES=DRIVES+=1
Set COUNT=1
Set HDD=sdb
:LOOP
echo . >> "C:\Results\Drive Temps at %TEMP%.txt"
echo . >> "C:\Results\Drive Temps at %TEMP%.txt"
echo Drive %COUNT% >> "C:\Results\Drive Temps at %TEMP%.txt"
smartctl -i -A %HDD% >> "C:\Results\Drive Temps at %TEMP%.txt"
IF %HDD%==sdx SET HDD=sdy
IF %HDD%==sdw SET HDD=sdx
IF %HDD%==sdv SET HDD=sdw
IF %HDD%==sdu SET HDD=sdv
IF %HDD%==sdt SET HDD=sdu
IF %HDD%==sds SET HDD=sdt
IF %HDD%==sdr SET HDD=sds
IF %HDD%==sdq SET HDD=sdr
IF %HDD%==sdp SET HDD=sdq
IF %HDD%==sdo SET HDD=sdp
IF %HDD%==sdn SET HDD=sdo
IF %HDD%==sdm SET HDD=sdn
IF %HDD%==sdl SET HDD=sdm
IF %HDD%==sdk SET HDD=sdl
IF %HDD%==sdj SET HDD=sdk
IF %HDD%==sdi SET HDD=sdj
IF %HDD%==sdh SET HDD=sdi
IF %HDD%==sdg SET HDD=sdh
IF %HDD%==sdf SET HDD=sdg
IF %HDD%==sde SET HDD=sdf
IF %HDD%==sdd SET HDD=sde
IF %HDD%==sdc SET HDD=sdd
IF %HDD%==sdb SET HDD=sdc
Set /a COUNT=COUNT+=1
IF %COUNT% EQU %DRIVES% GoTo :END
Goto :LOOP
:END
pause

 

 

We have a bit of software called smartctl that we use to get data from drive SMART in a storage enclosure attached to the host. We obviously don't want to know the C drive data so it starts at 'sdb', then goes up from there. I'm sure I could remove all those IFs and replace with a FOR but no idea how, can you increment a letter? There must be other ways to neaten it as well?

 

 

//edit: Ooh I've just realised I can swap my "Set /a COUNT=COUNT+=1" and "IF %COUNT% EQU %DRIVES% GoTo :END", and then I can remove my "Set /a DRIVES=DRIVES+=1"!

Link to comment
Share on other sites

Maybe.

Is this just one server then, with a pretty-much static list of drives? I'd use a reference file to list out the drives, then use vbs to read the list line by line and pass the entry into the smartctl command. Loads of sample scripts on the web to tell you how to do that and it'll make for about a 4 line script.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue. You might also be interested in our Guidelines, Privacy Policy and Terms of Use.