You can use the AT command in Windows to schedule chkdsk to automatically run on a daily basis. The problem with...
this technique is that chkdsk results are quickly flashed on the screen, then disappear. If you're not sitting at the server console when chkdsk runs, you won't ever see the scan results.
A better solution would be to create a batch file that logs the chkdsk results, so you can read those results at your leisure. I've used the following command to automate chkdsk:
AT \\Server1 3:00 /Interactive /every:Friday CHKDSK C:
This command runs chkdsk every Friday at 3:00 a.m. The command is set up to call chkdsk directly. But if you want to log the results, you'll need to tweak this command so that rather than calling chkdsk directly, it calls a batch file that in turn calls chkdsk.
You can name the batch file anything you want. Here we'll call it DRIVSCAN.BAT. Now we'll alter the AT command so it calls DRIVSCAN.BAT instead of chkdsk. The new command will look like this:
AT \\Server1 3:00 /Interactive /every:Friday DRIVSCAN.BAT
Now that we've changed our AT command to call a batch file, we need to create a batch file named DRIVSCAN.BAT. There are several methods for creating batch files; the easiest to use is probably Notepad. When you save your batch file, you must save it to a folder in the system path so the AT command can find it.
Exporting the results of a chkdsk to a log file is simple. In a command-line environment, placing the greater than (>) symbol at the end of a command tells Windows to export the command's results. You can complete the process by following the > sign with the filename you want the command results sent to. For example, if you wanted the chkdsk results exported to a file named SCAN.LOG, you'd use the following command:
CHKDSK > SCAN.LOG
You could use the command shown above as the only command in the DRIVSCAN.BAT file, and the batch file would work fine. The problem is you've told Windows (through the AT command) that you want to run the batch file every Friday at 3:00 a.m. The first time the command runs, the SCAN.LOG file will be created. But the second time the batch file runs, the chkdsk results will be appended to the end of the log file. In some environments, this behavior might be perfectly acceptable, but I prefer to place each set of chkdsk results in its own unique log file. This means that each time the batch file runs, it must generate a unique filename.
The easiest way to accomplish this is to base the filename on the date. The following command will help us create a filename based on the system date. The command takes the date, puts it in MMDDYYYY format and appends the .LOG extension. The date with the .LOG extension is assigned to a variable named datefile. For example, on July 1, 2007 the datefile variable would contain: 07012007.LOG
The command for setting up the datefile variable is:
for /F "tokens=2,3,4 delims=/ " %%i in ('date /t') do set datefile=%%i%%j%%k.log
If you want to view the contents of the datefile variable, you can do so by using the echo command. Since datefile is a variable, you must place percentage signs on each end of it any time you reference it. For example, the command for viewing the contents of this variable would be:
But we're not interested in merely viewing the contents of the datefile variable. Our goal is to use the variable's contents as a filename, and to export the chkdsk results to the file that is referenced by the datefile variable. To do so, use this command:
Chkdsk > %datefile%
The batch file in its entirety would look like this:
for /F "tokens=2,3,4 delims=/ " %%i in ('date /t') do set datefile=%%i%%j%%k.log Chkdsk > %datefile%
You could easily add a file system path to the batch file if you wanted to place the log files in a specific folder. There are several ways to do this, but the easiest is to include the path information as a part of the chkdsk command. Here's an example of the chkdsk command with a path added below:
Chkdsk > c:\logs\%datefile%
In this article I've shown you how to log the results of each chkdsk scan. However, you still have to go to each individual server to read the logs. My next article will show you how to modify the batch file we've created so that the server will automatically email you the scan results.
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.