Method "File exists" Reply
Method "File exists" Reply
I added a couple of tests regarding file age.
Unfortuately there is no reply value. Could you please add it? I check if a file is not older that 12 Months. I see if the test is ok or not but i have to calculate the difference by hands which is not comfortable.
Unfortuately there is no reply value. Could you please add it? I check if a file is not older that 12 Months. I see if the test is ok or not but i have to calculate the difference by hands which is not comfortable.
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
You may use Shell Script test for this task: http://www.ks-soft.net/hostmon.eng/mfra ... m#chkShell
Script may look like the following:
Start cmd: cmd /c cscript /B /E:JScript %Script% %Params%
Script requires 2 parameters: <file path> <max file age>
Script returns reply with value <max file age> - <file age>
Shell Script params examples:
D:\logs\dataLog.log 90
"D:\old logs\dataLog.log" 180
Script may look like the following:
Code: Select all
statusUnknown = "ScriptRes:Unknown:"
statusOk = "ScriptRes:Ok:"
statusBad = "ScriptRes:Bad:"
var objArgs = WScript.Arguments;
if (objArgs.length != 2) {
WScript.StdOut.Write(statusUnknown + "Required 2 parameters: <file path> <max file age>");
WScript.Quit;
}
var moddate;
var fname = objArgs(0);
var maxAge = parseInt(objArgs(1));
try {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var f = fso.GetFile(fname);
moddate = f.DateLastModified;
} catch(e) {
WScript.StdOut.Write(statusUnknown+ e.message+' ['+fname.replace(/\\\\/g,'\\')+']');
WScript.Quit;
}
var dat = new Date;
var fileAge = parseInt((dat - moddate)/1000/60/60/24); //difference in days
var replyval = maxAge-fileAge;
if (fileAge>maxAge) {
WScript.StdOut.Write(statusBad+replyval);
} else {
WScript.StdOut.Write(statusOk+replyval);
}
Script requires 2 parameters: <file path> <max file age>
Script returns reply with value <max file age> - <file age>
Shell Script params examples:
D:\logs\dataLog.log 90
"D:\old logs\dataLog.log" 180
Also we added 3 variables related to Folder/File Availability test method:
%FileAge_Min% - age of the file in minutes
%FileAge_Hour% - age of the file in hours
%FileAge_Day% - age of the file in days
Variables can be used as parameter of some actions, for Optional status processing, reports, etc
If you are using latest version of the software (10.30), you may download update at
www.ks-soft.net/download/hm1031.zip
Regards
Alex
%FileAge_Min% - age of the file in minutes
%FileAge_Hour% - age of the file in hours
%FileAge_Day% - age of the file in days
Variables can be used as parameter of some actions, for Optional status processing, reports, etc
If you are using latest version of the software (10.30), you may download update at
www.ks-soft.net/download/hm1031.zip
Regards
Alex
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
The tuneup is only for adding a descriptive string to the suggestedReply variable
Yes i tested the new version and the variables. Thanks for your additions.
Your new variable %FileAge_Day% computes the difference between filedate and now, whereas your script computes the difference between now and the future day.
The latter is exactly what i wanted.
To use the new variables one must be able to compute with dates. Maybe something like that:
%Date%-(%FileDate%+%TestTime%) ???
Yes i tested the new version and the variables. Thanks for your additions.
Your new variable %FileAge_Day% computes the difference between filedate and now, whereas your script computes the difference between now and the future day.
The latter is exactly what i wanted.
To use the new variables one must be able to compute with dates. Maybe something like that:
%Date%-(%FileDate%+%TestTime%) ???
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact: