View previous topic :: View next topic |
Author |
Message |
menno
Joined: 21 May 2010 Posts: 157
|
Posted: Thu Jan 28, 2016 3:16 am Post subject: check windows defrag analysis |
|
|
Hello all
i want to make a check that checks the output of the dos-box command.
i want to check , and HM reply , the last line from the defrag command.
Here is the example from the dos-box :
Code: |
C:\Users\Administrator>defrag c: /a
Microsoft Drive Optimizer
Copyright (c) 2013 Microsoft Corp.
Invoking analysis on (C:)...
The operation completed successfully.
Post Defragmentation Report:
Volume Information:
Volume size = 49,99 GB
Free space = 37,35 GB
Total fragmented space = 30%
Largest free space size = 30,66 GB
Note: File fragments larger than 64MB are not included in the fragmentation statistics.
It is recommended that you defragment this volume.
|
is it possible to get this line in the Reply field of HM ?
It is recommended that you defragment this volume.
or better
Total fragmented space = 30%
and then in this case 30%
I allready played with some scripts but i did not find the solution.
Can you please help me ?
Many many thanks in advance
M
Last edited by menno on Thu Jan 28, 2016 5:34 am; edited 2 times in total |
|
Back to top |
|
|
SplanK
Joined: 21 Nov 2007 Posts: 38
|
Posted: Thu Jan 28, 2016 5:00 am Post subject: |
|
|
You could make a VBS script which captures the output of the text, loops through it and processes it.
The below (bit messy sorry) example is an example of looking through the output of Ipconfig and sets a variable to 1 if it finds "192.168." within the output.
Code: |
set WSHShell = WScript.CreateObject("WScript.Shell")
Set oExec = WshShell.Exec("cmd /c ipconfig")
Do until oExec.Stdout.atEndOfStream
oReadLine = oExec.StdOut.ReadLine
If instr(oReadLine, "192.168.") > 0 Then
oNetExtenderFound = 1
End If
Loop
wscript.echo oNetExtenderFound |
|
|
Back to top |
|
|
menno
Joined: 21 May 2010 Posts: 157
|
Posted: Thu Jan 28, 2016 5:28 am Post subject: |
|
|
thanks splank but this not what i want
if i do a : defrag c: /a in the output there is (as example) :
Total fragmented space = 24%
I just want somthing like :
if "fragmented space" is greater than xx% then test is BAD
or just only the "fragmented space" in the Reply field
can someone ( most of the time Alex ) make this happen for me ?
many thanks in advance
menno |
|
Back to top |
|
|
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
Posted: Thu Jan 28, 2016 1:55 pm Post subject: |
|
|
You may use the following JS script with Shell Script test method:
Code: | // Script requires 0,1 or 2 parameters: [disk letter [max defreg threshold]]
statusUnknown = "scriptRes:Unknown:";
statusOk = "scriptRes:Ok:";
statusBad = "scriptRes:Bad:";
objArgs = WScript.Arguments;
var max = 101;
var hdd = 'c';
if (objArgs.length==1) {
hdd = objArgs(0);
}
if (objArgs.length>1) {
hdd = objArgs(0);
max = parseInt(objArgs(1));
}
try {
var WshShell = new ActiveXObject("WScript.Shell");
var cmd = WshShell.Exec('cmd /c defrag '+hdd+': /a');
while (cmd.Status === 0) {
WScript.Sleep(100);
}
var output = cmd.StdOut.ReadAll();
} catch(e) {
WScript.StdOut.Write(statusUnknown + e.Message);
WScript.Quit();
}
if (output.indexOf('Total fragmented space')==-1) {
WScript.StdOut.Write(statusUnknown + "Incorrect output.");
WScript.Quit();
}
if (max==101) {
if (output.indexOf("recommended that you defragment")>-1) {
max = 0;
}
}
output=output.substr(output.indexOf("Total fragmented space"));
output=output.substr(output.indexOf("="));
output=output.substr(1,output.indexOf("%")-1);
output=output.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); // trim()
var val = parseInt(output);
if (val>max) {
WScript.StdOut.Write(statusBad + val + " %");
} else {
WScript.StdOut.Write(statusOk + val + " %");
} |
start CMD on 64-bit OS: C:\Windows\sysnative\cmd /c cscript /B /E:JScript %Script% %Params%
start CMD on 32-bit OS: cmd /c cscript /B /E:JScript %Script% %Params%
Script requires 0, 1 or 2 parameters: [disk letter [max defreg threshold]]
Several examples:
<no parameters specified> - script will check fragmentation of c drive
d - script will sheck fragmentation % of drive d
c 11 - script will check drive c for fragmentation percent and set Bad status if fregmented space is more than 11 % (script will ignore defrag recommendation) |
|
Back to top |
|
|
menno
Joined: 21 May 2010 Posts: 157
|
Posted: Fri Jan 29, 2016 5:32 am Post subject: |
|
|
thanks this works fine !
menno |
|
Back to top |
|
|
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
Posted: Fri Jan 29, 2016 10:10 am Post subject: |
|
|
You are welcome! |
|
Back to top |
|
|
|