Solved

Rotate Scheduled Task log file

Posted on 2006-11-24
8
556 Views
Last Modified: 2012-05-05
Is there a way to rotate/archive the scheduled task log file?
0
Comment
Question by:jst3751
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
Recently, I had the need to build a standalone system to run a point-of-sale system. I’m running this on a low-voltage Atom processor, so I wanted a light-weight operating system, but still needed Windows. I chose to use Microsoft Windows Server 200…
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

729 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