tbourner Posted September 29, 2010 Share Posted September 29, 2010 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"! Quote Link to comment Share on other sites More sharing options...
AlexJames Posted September 29, 2010 Share Posted September 29, 2010 ... thats exactly what I was about to say! Quote Link to comment Share on other sites More sharing options...
Ark Posted September 29, 2010 Share Posted September 29, 2010 Is this a *NIX system in the background? Quote Link to comment Share on other sites More sharing options...
tbourner Posted September 29, 2010 Author Share Posted September 29, 2010 Nope, Windows Server 2003. Would probably be a lot easier if it was on our Linux tester. Quote Link to comment Share on other sites More sharing options...
Ark Posted September 30, 2010 Share Posted September 30, 2010 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. Quote Link to comment Share on other sites More sharing options...
tbourner Posted September 30, 2010 Author Share Posted September 30, 2010 Well it's a file we want to add to a self extracting program that we can load onto any of our test PCs. The servers we attach are anything from 12 to 24 drives, but always starting from sdb, the user needs to be able to input the number of drives for it to test though. Quote Link to comment Share on other sites More sharing options...
Ark Posted September 30, 2010 Share Posted September 30, 2010 Ok so evaluate the list of drives programatically each time the script runs. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.