Home > Windows Server Tips > Windows Systems Management and Administration > Create a script to check integrity of your server's drives
Windows Server Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

WINDOWS SYSTEMS MANAGEMENT AND ADMINISTRATION

Create a script to check integrity of your server's drives


Brien M. Posey, Site Expert
08.23.2007
Rating: -3.75- (out of 5)


Expert advice on Windows-based systems and hardware
Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


So far in this series on detecting the integrity of your hard drive, I've shown you how to perform an automated chkdsk and dump the results to a report file. There's still one problem: Each server you run the script on ends up containing its own copy of the log file.

One way to resolve this problem is to adjust the script's output path, by directing the log files to a folder on a network drive. The script could also be adjusted to include the server's name as part of the file name. This way, you'd know which server generated each report.

This technique has a downside: You have to remember to review the logs periodically. It's better to configure the script so it emails the report to you.

Although Microsoft has released a few obscure utilities that let you send an email message from a command prompt, third-party utilities make the process easier. A company called Febooti makes a utility called Command Line Email that lets you send email messages from a command prompt. Licenses for this product cost less than $45, but I've seen them offered for $25 on some Web sites.

The basic syntax for this utility is:

FEBOOTIMAIL –FROM sender's e-mail address –
TO recipient's e-mail address –SUBJECT message subject –
TEXT message body –ATTACH filename

The command syntax is fairly straightforward. But before you add the FEBOOTIMAIL command to your script, I recommend creating an email address for each of your servers. This way, when the messages arrive in your inbox, there'll be no doubt as to which server sent it. In this article, I'll use Server1@contoso.com as the sender's address, and admin@contoso.com as the recipient's address.

Now let's look at how we can integrate the FEBOOTIMAIL command into our script. As you might recall, our batch file currently looks like this:

for /F "tokens=2,3,4 delims=/ " %%i in ('date /t') do set datefile=%%i%%j%%k.log
Chkdsk C: >c:\logs\ %datefile%

Assuming we want to email a report from a server named Server1, we could append the following command to the file:

FEBOOTIMAIL –FROM server1@contoso.com –
TO admin@contoso.com –SUBJECT Drive Integrity Report –
TEXT Here is today's drive integrity report for Server1 –ATTACH c:\logs\%datafile%

This command takes the report that was just created, attaches it to an email message and sends it to the administrator.

In the real world, you might encounter other issues with this technique, such as your mail server requiring authentication. I can't give you the specifics for this technique, because the necessary authentication commands vary from one organization to the next. I recommend attempting the command without authentication first. If that doesn't work, here's Febootimail's full command syntax.

Another issue relates to scanning multiple hard drives. Almost every server has more than one drive, yet our command only scans the server's C: drive. But this is easy to remedy -- simply add another chkdsk line for each drive letter you want to scan. For example, if you wanted to scan the C: and the D: drives, your script would look like this:

for /F "tokens=2,3,4 delims=/ " %%i in ('date /t') do set datefile=%%i%%j%%k.log
Chkdsk  C: >c:\logs\ %datefile%
Chkdsk  D: >>c:\logs\ %datefile%
FEBOOTIMAIL –FROM server1@contoso.com –
TO admin@contoso.com –SUBJECT Drive Integrity Report –
TEXT Here is today's drive integrity report for Server1 –ATTACH c:\logs\%datafile%

Note: In the second chkdsk command, I've changed the drive letter to D: and used two > (greater than) signs to redirect the command's output. A single > sign tells the script to create a file; two of them tell the script to append the output to a file that's already been created.

One problem with including multiple scans into a single log file is that chkdsk does not report which drive it is scanning. I recommend inserting some comments into the command that will tell you which drive each section of the file pertains to.

To do this, use the ECHO command, which simply repeats whatever text follows it. If you were to type ECHO HELLO, the output would be HELLO. However, output from an ECHO command can be redirected to a file, and this provides a good way to insert notations into your log file. For example, if I wanted to flag the beginning of the D: drive scan, I could insert the following lines into the script:

ECHO . >>c:\logs\ %datefile%
ECHO ………………………..CHKDSK
D:…………………………… >>c:\logs\ %datefile% ECHO. >>c:\logs\ %datefile%

Using the ECHO command to insert a blank line is difficult, because it involves inserting a null character. This is hard to show here, because the null character is invisible. So instead, I simply use a period in the first and last line, so that ECHO will insert an almost blank line into the file.

The complete script for reporting the integrity of your server's drive and emailing the report to you looks like this:

for /F "tokens=2,3,4 delims=/ " %%i in ('date /t') do set datefile=%%i%%j%%k.log
Chkdsk  C: >c:\logs\ %datefile%
ECHO . >>c:\logs\ %datefile%
ECHO …………………………..CHKDSK
D:…………………………… >>c:\logs\ %datefile% ECHO. >>c:\logs\ %datefile% Chkdsk D: >>c:\logs\ %datefile% FEBOOTIMAIL –FROM server1@contoso.com –
TO admin@contoso.com –SUBJECT Drive Integrity Report –
TEXT Here is today's drive integrity report for Server1 –ATTACH c:\logs\%datafile%

About the author: Brien M. Posey, MCSE, is a Microsoft Most Valuable Professional for his work with Windows 2000 Server, Exchange Server and IIS. He has served as CIO for a nationwide chain of hospitals and was once in charge of IT security for Fort Knox. He writes regularly for SearchWinComputing.com and other TechTarget sites.

More information on this topic:


Rate this Tip
To rate tips, you must be a member of SearchWindowsServer.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us    Add to Google


RELATED CONTENT
Microsoft Windows Scripting Language
Scripting elevation in Windows Vista with JavaScript
Use Ldifde.exe and Csvde.exe data export tools to create Active Directory objects
Scripting School: Replacing text with regular expressions
Scripting School: Writing a script for an office inventory system
Christa Anderson's Scripting School for Windows administrators
How to automate advanced Windows desktop tasks using scripts and macros
Just the FAQs guide to VB Scripting basics
Script reveals which port Terminal Services listens to for incoming connections
Scripting School: Find objects with Windows Script Host
Windows scripting for beginners

Disk Drives and Disk Arrays for Windows
Case Study: Building a low-cost SATA array
How to use the g4u network-based hard disk cloning utility
Can freezing a hard drive that's crashed restore it to life?
Move from PATA to SATA could complicate data recovery
Use RAID to increase write performance on three-drive arrays
Stop disk drive overload to increase system performance
A Windows administrator's guide to Diskpart commands
Use RoboCopy to copy files from crashed hard disk drives
Findpart utility locates lost partitions on disk
Give domain users permission to do disk defragmentation locally

Windows Systems Management and Administration
Tips for Windows domain controller optimization
Quick hits: Troubleshooting service account failure, batch job execution
Case Study: Troubleshooting Windows service dependency failures
Troubleshooting common Windows service failures
How to format NTFS: More tricks to improve file system performance
Key enhancements to SCCM give admins more control over assets, licensing
Windows scripting secrets for disk quota management
Optimizing NTFS file system performance
Debugging Userenv issues using Windows new event viewer
The new Microsoft System Center: What happened to SMS and MOM?

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Server Room Design - Planning, Cooling, Maintenance
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersIT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides enterprise IT professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective IT purchase decisions and managing their organizations' IT projects - with its network of technology-specific Web sites, events and magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 2004 - 2009, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts