KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

Check last modify time of growing log files

 
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting
View previous topic :: View next topic  
Author Message
Stefan



Joined: 11 Feb 2011
Posts: 19

PostPosted: Fri Mar 13, 2015 4:13 am    Post subject: Check last modify time of growing log files Reply with quote

Hello KS-support team,

I have a problem to identify several log files.
I want to check the age (last modify time) of the newest file with "Folder/File Availability"-test.

In the following I want to show you the structure of log files which are
located !!!only in one!!! directory.

---------------------------------------------------------------
"Control_3_PROD20150313.0" (50MB - old log file)
"Control_3_PROD20150313.1" (newest log file)

"Control_5_PROD20150313.0" (50MB - old log file)
"Control_5_PROD20150313.1" (newest log file)

"Control_13_PROD20150313.0" (50MB - old log file)
"Control_13_PROD20150313.1" (newest log file)
---------------------------------------------------------------

Unfortunately, the system, which generate log files, will create new log-file by reaching size of 50 MegaBytes and increase ending number of filename.
So, if I use the path-string "\\[SERVER-IP]\[DIRECTORY-NAME]\Control_3_PROD%yyyy%%mm%%dd%.*" with enabled macro translation,
HostMonitor can not identify the newest log-file.

Can you help me to find the way to identify always the growing log-files?

Regards,
Stefan
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12807
Location: USA

PostPosted: Fri Mar 13, 2015 6:23 am    Post subject: Reply with quote

Use another variable: %NewestFile% - Name of the newest file in specified folder
\\SERVER-IP\DIRECTORY-NAME\%NewestFile%

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
Stefan



Joined: 11 Feb 2011
Posts: 19

PostPosted: Fri Mar 13, 2015 7:01 am    Post subject: Reply with quote

Hi Alex,

my problem is, that into the same directory, there are more than one log-files which grows continuely.
So I can not use %NewestFile% variable because HostMonitor will check always one of all growing log-files?

Regards,
Stefan
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12807
Location: USA

PostPosted: Fri Mar 13, 2015 8:28 am    Post subject: Reply with quote

Sorry, I do not understand.
You said you want to check newest file (using modification timestamp). Then you need to use %newestfile% variable.

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
Stefan



Joined: 11 Feb 2011
Posts: 19

PostPosted: Mon Mar 16, 2015 2:47 am    Post subject: Reply with quote

Hi Alex,

sorry for my bad description.

I want to check newest file of each log-file.
But unfortunately, there are all three log-files into same directory! (see following example)

---------------------------------------------------------------
"Control_3_PROD20150313.0" (50MB - old log file)
"Control_3_PROD20150313.1" (newest log file)

"Control_5_PROD20150313.0" (50MB - old log file)
"Control_5_PROD20150313.1" (newest log file)

"Control_13_PROD20150313.0" (50MB - old log file)
"Control_13_PROD20150313.1" (newest log file)
---------------------------------------------------------------

Which file will HostMonitor check by using %NewestFile% Variable? (Always the newest one ???)

Regards,
Stefan
Back to top
View user's profile Send private message
KS-Soft



Joined: 03 Apr 2002
Posts: 12807
Location: USA

PostPosted: Mon Mar 16, 2015 7:59 am    Post subject: Reply with quote

Oh, I see - application records 3 log files at the same time and there is no fixed name for each log file?
Then I do not see solution.
Unless you can change application settings so it will use different folders for these log files.

Regards
Alex
Back to top
View user's profile Send private message Visit poster's website
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Mon Mar 16, 2015 3:54 pm    Post subject: Reply with quote

Actually this can be done using custom script with Shell Script test method.
What is expected Reply (e.g. file age in minutes, or just time string)
What threshold condition should look like? (e.g. set Bad status if file is older than 30 min.)
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Stefan



Joined: 11 Feb 2011
Posts: 19

PostPosted: Tue Mar 17, 2015 3:25 am    Post subject: Reply with quote

Hello KS-Soft Europe team,

it would be great if you can show me an example of using a custom script with shell script test method!
As reply I expect the file age in minutes and threshold condition to set bad status should be file age is older than 15 minutes.

Regards,
Stefan
Back to top
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Tue Mar 17, 2015 5:25 am    Post subject: Reply with quote

JScript for Shell Script test method may look like the following:
Code:
statusUnknown     = "ScriptRes:Unknown:"
statusOk          = "ScriptRes:Ok:"
statusBad = "ScriptRes:Bad:"

objArgs = WScript.Arguments;

if (objArgs.length<3) {
  WScript.StdOut.Write(statusUnknown + 'Required 3 parameters: <folder path> <partial file name e.g.: TEST03> <age in minutes>');
  WScript.Quit();
}

  var oFS = new ActiveXObject('Scripting.FileSystemObject');
  var ff1 = oFS.GetFolder(objArgs(0));
  var fc = new Enumerator(ff1.files);
  var newestFile = false;
  var newestTime = false;

  for (; !fc.atEnd(); fc.moveNext())
    {
     if (newestFile === false&&fc.item().name.indexOf(objArgs(1))>-1) {
        newestTime = fc.item().DateLastModified;
        newestFile = fc.item();
        }

     if (fc.item().DateLastModified > newestTime&&fc.item().name.indexOf(objArgs(1))>-1) {
        newestTime = fc.item().DateLastModified;
        newestFile = fc.item();
        }
    }

    if (newestFile === false) {
      WScript.StdOut.Write(statusUnknown + 'No files found with name like ('+objArgs(1)+')');
       WScript.Quit();
      }
   
     var dat = new Date;
     var fileAge = parseInt((dat - newestTime)/1000/60);

     if (fileAge > parseInt(objArgs(2))) {
       WScript.StdOut.Write(statusBad+fileAge+' ('+newestFile.name+')');
       WScript.Quit();
     }

   WScript.StdOut.Write(statusOk+fileAge);

Start cmd: cmd /c cscript /B /E:JScript %Script% %Params%
Script requires 3 parameters: <folder path> <partial file name e.g.: Control_6_PROD> <age in minutes>
E.g.:
"\\SERVER-IP\DIRECTORY-NAME\" Control_13_ 15
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Stefan



Joined: 11 Feb 2011
Posts: 19

PostPosted: Tue Mar 17, 2015 9:49 am    Post subject: Reply with quote

Hello KS-Soft Europe team,

thank you very much for your Jscript-code!!!
It is working very well

Great support!!! Thanks!!!

Regards,
Stefan
Back to top
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Tue Mar 17, 2015 10:06 am    Post subject: Reply with quote

You are welcome!
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group

KS-Soft Forum Index