SoftTree Technologies SoftTree Technologies
Technical Support Forums
RegisterSearchFAQMemberlistUsergroupsLog in
Archiving/Clearing scheduler.log File Query

 
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite View previous topic
View next topic
Archiving/Clearing scheduler.log File Query
Author Message
LouGibson



Joined: 21 May 2013
Posts: 8
Country: United Kingdom

Post Archiving/Clearing scheduler.log File Query Reply with quote
I'd like to implement a script which archives the scheduler.log file to a designated folder then clears it down ready for the new day's log messages. I've followed the suggestions from pages 296/297 of the User's Guide and Job Automation Language (JAL) Reference manual and incorporated them into a JAL script show below. The FileCopy part of the script works fine but the FileDelete fails - presumably as the file is still opened by the scheduler. Is there any way of closing the scheduler.log file temporarily to enable it to be cleared down? Thanks.

Dim run_date, date
Dim run_time, time
Dim file_date, datetime
Dim copy_path, string
Dim date_part, string
Today(run_date)
Now(run_time)
DateTime(run_date,run_time,file_date)
Format(file_date,"yyyymmdd",date_part)
Concat("E:\SoftTree24x7\24x7\LogArchive\scheduler-",date_part,copy_path)
ConCat(copy_path,"-",copy_path)
Format(file_date,"hhmmss",date_part)
ConCat(copy_path,date_part,copy_path)
ConCat(copy_path,".log",copy_path)
FileCopy "E:\SoftTree24x7\24x7\scheduler.log", copy_path
FileDelete "E:\SoftTree24x7\24x7\scheduler.log"
Mon Jun 17, 2013 8:29 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7840

Post Reply with quote
Please try renaming the file and then deleting the renamed file a minute later using a different job
Mon Jun 17, 2013 12:56 pm View user's profile Send private message
LouGibson



Joined: 21 May 2013
Posts: 8
Country: United Kingdom

Post Reply with quote
Thanks for the quick response. The rename also fails "An error occurred while executing automation script Line 1:Line 16:Error renaming file."
Tue Jun 18, 2013 8:48 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7840

Post Reply with quote
Are you sure this is a file locking issues? Please try giving yourself full explicit permissions for 24x7 folder.
Tue Jun 18, 2013 4:23 pm View user's profile Send private message
LouGibson



Joined: 21 May 2013
Posts: 8
Country: United Kingdom

Post Reply with quote
I'm pretty sure this is a locking issue; I've granted Full Control to the 24x7 folder and the problem persists. If I try renaming the file using Windows Explorer I get a "The action can't be completed because the file is open in Java(TM) Platform SE binary - Close the file and try again" message. Thanks.
Wed Jun 19, 2013 3:54 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7840

Post Reply with quote
Well, I've done some testing and I'm observing the same behavior. I found out that the scheduler.log file can not be deleted because it's locked in read/write mode, but the contents of the file can be truncated to a zero size effectively restarting the log, which is what you are after, right? There are no built-in commands in 24x7 to set file length or truncate contents, but I've found a site offering tons of examples for truncating file content. Please take a look here http://rosettacode.org/wiki/Truncate_a_file
Perhaps you can use one of these examples and create a small command line utility that you can call from the job


Last edited by SysOp on Wed Jun 19, 2013 7:57 am; edited 1 time in total
Wed Jun 19, 2013 7:54 am View user's profile Send private message
LouGibson



Joined: 21 May 2013
Posts: 8
Country: United Kingdom

Post Reply with quote
I'll give that a go, many thanks for your help.
Wed Jun 19, 2013 7:56 am View user's profile Send private message
LouGibson



Joined: 21 May 2013
Posts: 8
Country: United Kingdom

Post Reply with quote
I adapted the C# example from rosettacode.org but the resulting app still throws an error:

E:\TMS_IT\Batch\Command>TruncateFile.exe "E:\SoftTree24x7\24x7\scheduler.log" 0
TruncateFile: The process cannot access the file 'E:\SoftTree24x7\24x7\scheduler.log' because it is being used by another process.
E:\TMS_IT\Batch\Command>

Could you raise this as a bug please. We would like to keep a log history but as it stands the log file can only be cleared manually. Thanks.
Wed Jun 19, 2013 9:00 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7840

Post Reply with quote
Let me try the C# example and tweak it to work. If we can truncate the log file using Notepad, we should be able to do the same programmatically too
Wed Jun 19, 2013 11:34 am View user's profile Send private message
barefootguru



Joined: 10 Aug 2007
Posts: 195

Post Reply with quote
I haven't paid much attention to when it actually happens, but on Windows the 24x7 service can archive the log when you stop & start it, e.g. to scheduler-20130623-165844.log Might be an option?
Mon Jun 24, 2013 12:34 am View user's profile Send private message
LouGibson



Joined: 21 May 2013
Posts: 8
Country: United Kingdom

Post Reply with quote
If stopping and starting the scheduler requires manual intervention then no, what I'm looking for is a means of archiving and clearing the log file that can be run by the scheduler itself. Thanks.
Mon Jun 24, 2013 1:11 am View user's profile Send private message
SysOp
Site Admin


Joined: 26 Nov 2006
Posts: 7840

Post Reply with quote
Here is the code that will truncate the file. You should specify Read-write share mode when opening the file otherwise your C# program try to use the default mode which is to open file in exclusive access mode and that will throw file-in-use exception


Code:
using System;
using System.IO;

namespace TruncateFile
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            if (args.Length < 1)
                throw new ArgumentException("File name not specified. Usage Truncatefile <file>");
            TruncateFile(args[0]);
        }

        private static void TruncateFile(string path)
        {
            if (!File.Exists(path))
                throw new ArgumentException("No file found at specified path.", path);

            using (var fileStream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))
            {
                fileStream.SetLength(0);
            }
        }
    }
}

Mon Jun 24, 2013 7:56 am View user's profile Send private message
LouGibson



Joined: 21 May 2013
Posts: 8
Country: United Kingdom

Post Reply with quote
Works perfectly, many thanks for your help. Regards.
Mon Jun 24, 2013 8:28 am View user's profile Send private message
Display posts from previous:    
Reply to topic    SoftTree Technologies Forum Index » 24x7 Scheduler, Event Server, Automation Suite All times are GMT - 4 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
Design by Freestyle XL / Flowers Online.