Solved

Rotate Scheduled Task log file

Posted on 2006-11-24
8
543 Views
Last Modified: 2012-05-05
Is there a way to rotate/archive the scheduled task log file?
0
Comment
Question by:jst3751
  • 5
  • 3
8 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18009407
I presume you mean the SchedLgU.Txt file in windows directory?  If so it does rotate around afaik keeping around 32k in size, as in it overwrites itself leaving a line such as this in the file :

[ ***** Most recent entry is above this line ***** ]

Nothing stopping you creating a batch file which copies this somewhere else then scheduling it, e.g. schedule a job to run once a day, week or month which runs a batch file something like this:

@echo off
REM Copy schedule log to fil e
mkdir C:\sch-logs 2>NUL
net stop "task scheduler"
copy "%windir%\schedlgu.txt" "c:\sch-logs\%date:/=-%.txt"
del "%windir%\schedlgu.txt"
net start "task scheduler"

0
 
LVL 1

Author Comment

by:jst3751
ID: 18009961
But how can you stop the "Task Schedule" service when you are running a job that is called by it?
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18009993
Haven't tried it but by the time the job is started it should be a separate task in memory and continue... will have a check over the weekend if I get a chance.
You could always run the job on another server under its task scjeduler and use sc.exe to stop the service on the other box and access the log file using the unc path...

What are you after here?
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 1

Author Comment

by:jst3751
ID: 18010001
I have a number of tasks that run multiple times per day which quickly overwrite task log lines more than 12 hours old. I would like to be able to review say 10 days worth of logs.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18010061
Ok, well you can certainly copy the logs without stopping the scheduler as long as it doesn't get deleted ... late now will check back tomorrow.
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 125 total points
ID: 18015516
Ok, using the batch file above I was able to have it stop the task scheduler from a scheduled job itself, copy and delete the log file and restart the scheduler.  Another scheduled job that had already been started continued running fine while the scheduler restarted as expected.  I adjusted the batch file so that it appends the log file each time it is run to the end of the current day's log archive. The second part of the batch file then removes all but the most recent 10 files in that directory.

let me know if any of that needs explanation etc.

Steve

@echo off
REM Copy schedule log to file
mkdir C:\sch-logs 2>NUL
net stop "task scheduler"
copy "c:\sch-logs\%date:/=-%.txt"+"%windir%\schedlgu.txt" "c:\sch-logs\%date:/=-%.txt"
del "%windir%\schedlgu.txt"
net start "task scheduler"

REM Remove all but last ten log files:
for /f "skip=10 tokens=*" %%a in ('dir C:\sch-logs\*.txt /o-d /b') do echo del "c:\sch-logs\%%a"
0
 
LVL 1

Author Comment

by:jst3751
ID: 18017419
I like it, thanks, that will work.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 18017774
Glad you liked it, not keen on getting a B grade, especially on 125 points for a custom solution mind...

Steve
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

by Batuhan Cetin In this article I will be guiding through the process of removing a failed DC metadata from Active Directory (hereafter, AD) using the ntdsutil tool in a Windows Server 2003 environment. These steps are not necessary in a Win…
Many of us need to configure DHCP server(s) in their environment. We can do that simply via DHCP console on server or using MMC snap-in on each computer with Administrative Tools installed in a network. But what if we have to configure many DHCP ser…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question