Solved

Rotate Scheduled Task log file

Posted on 2006-11-24
8
551 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
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

Technology Partners: 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

Suggested Solutions

Preface Having the need * to contact many different companies with different infrastructures * do remote maintenance in their network required us to implement a more flexible routing solution. As RAS, PPTP, L2TP and VPN Client connections are no…
While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

733 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