• Home
  • About
Blue Orange Green Pink Purple

Scheduled task executable batch babysitter

Posted in Uncategorized. on Thursday, October 29th, 2009 by Chris Hulbert
Oct 29

Hi again,
When setting up scheduled tasks to run on an windows server, i've found it useful to wrap my executable with a batch file, which keeps track of logging all the console standard and error output. It redirects them to log files with a YYYYMMDD prefix, and deletes old logs too. The idea is that the scheduled task runs this batch instead of the executable directly:

md logs

echo ************************ >> logs\%date:~10,4%%date:~7,2%%date:~4,2%_MyJob.log
echo Starting - %date% %time% >> logs\%date:~10,4%%date:~7,2%%date:~4,2%_MyJob.log
MyJob.exe >> logs\%date:~10,4%%date:~7,2%%date:~4,2%_MyJob.log 2>&1
echo Ended    - %date% %time% >> logs\%date:~10,4%%date:~7,2%%date:~4,2%_MyJob.log
echo ************************ >> logs\%date:~10,4%%date:~7,2%%date:~4,2%_MyJob.log

rem *** Clean up 60 day old logs

Forfiles -p logs -m *.log -d -60 -c "cmd /c del @path"

Leave a Reply

Chris' Babble

  • About
    Hi, i'm Chris Hulbert, a software guy from Sydney Australia.
  • Categories
    • code
    • Portfolio
    • Uncategorized
  • Recent Articles
    • How to implement DES and Triple DES from scratch
    • How to use Cookies in Struts 2 with ServletRequest and ServletResponse
    • How to use sessions with Struts 2
    • Using Quartz Scheduler in a Java web app (servlet)
    • Javascript date picker that Doesn't Suck!(tm)
    • Using Oracle XE with Hibernate


  • Home
  • About

© Copyright Chris' Babble. All rights reserved.
Designed by FTL Wordpress Themes brought to you by Smashing Magazine

Back to Top