0

i need your help in putting together a batch script to monitor disk space on the logical drives and email if any of the drive crosses the threshold set.

I am unable to iterate and perform the calculations for each of the drives. How can i do it using the for loop and wmic or is there any other way of doing it?

user1204106
  • 1
  • 1
  • 1
  • Which platform are you using? Powershell + wmi could do this on windows. – Chriseyre2000 Feb 11 '12 at 18:26
  • I'm sure this could be done in batch, but I believe it would be more appropriate to use perfmon.exe. I've never used it, but I think this is the type of thing it is designed to do. Perhaps this would be a good question for the Super User (www.superuser.com) site instead. – dbenham Feb 11 '12 at 20:43

2 Answers2

1

This might help you on your way, but then you'd have to parse the string... which is a bit complicated for the command line.

C:\>dir | find "bytes free"
           9 Dir(s)  21,954,252,800 bytes free
demoncodemonkey
  • 11,730
  • 10
  • 61
  • 103
0

Are you married to wmic? If not, you could take a look at https://stackoverflow.com/a/2372171/1033808… which uses Python. To iterate over each of the drives, something like:

drive_list = ["c:","d:","e:"]
for drive in drive_list:
  free_space = get_free_space(drive)
  if free_space > threshold:
    send_mail("Drive %s crossed the threshold" % drive)

should do the trick. The send_mail function takes the body of the mail as input argument, see this python documentation for sending an email.

Community
  • 1
  • 1
Paul Hiemstra
  • 59,984
  • 12
  • 142
  • 149