Solved

Rotate Scheduled Task log file

Posted on 2006-11-24
8
534 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
 
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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

by Batuhan Cetin Within the dynamic life of an IT administrator, we hold many information in our minds like user names, passwords, IDs, phone numbers, incomes, service tags, bills and the order from our wives to buy milk when coming back to home.…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now