THE IDIOTS GUIDE TO ROTATING YOUR LOGS ON WINDOWS NT
0) Install cygwin32 tools from www.cygnus.com
The simplest thing is to get "userstools.exe" and install it.
This will give you all the nice UNIX commands you wish you had
anyway, along with the bash shell which you also wish you had
anway.
1) Make a batch file that looks like this
c:\cygnus\cygwin-b20\H-i586-cygwin32\bin\bash.exe
d:\logs\rotate.sh > d:\logs\rotate.out
Note, that should all be on one line, and remember to make funny
DOS style slashes.
2) Make a bash shell file in /logs called rotate.sh
cd d:/logs/
rm -f stdout.4
mv -f stdout.3 stdout.4
mv -f stdout.2 stdout.3
mv -f stdout.1 stdout.2
cp -f stdout.log stdout.1
echo "" > stdout.log
Note, these are all separate lines and remember to use
normal UNIX style slashes. The key line is the
echo "" > stdout.log
Also note, there is no first line like "#!/cygwin/.../bash.exe"
This is not the most elegant way to rotate log files, but it is
the only way I have found on NT, to date. Its bad because you have
to copy the current log file, which may be quite large.
3) Make sure you have the "Scheduler" service started in the services
control panel. If you aren't currently using it, you should start it
and then set it to start up at boot. (Start->Control->Panel->Services)
4) try it out, just type "rotate.bat" from within the jrun logs
directory
5) Using the "at" command from a DOS Shell (don't try this from a bash
shell) schedule the batch file to run every so often
at 13:30 d:\jrun\jsm-default\logs\rotate.bat
To see your list of scheduled items just type "at"
This is the NT equivalent of "cron" and I must say, it is a bit
more user-friendly.
6) sit back and relax.
Note: DOS has a copy, rename and echo command. I have not tried
these as I really don't ever work in DOS or know how to use many
of the DOS commands (nor do I really want to given the easy
availability of cygwin's unix tools) The DOS versions may or
may not work. I suspect when you try DOS echo you may get a
"Permission Denied - file in use" type error.Final Note: It shouldn't be necessary to make the batch file. You should be able to schedule the shell file ( rotate.sh ) using "at". I was able to do this on one computer, but not on another, so above I gave the more reliable form. In both cases I made sure that I set the .sh file type to be "Run" by default by bash.exe. I am not sure why it doesn't work in some cases.
Also, make sure you have the latest version of the cygwin32 tools. I had one version that wouldn't run scripts without saying "source rotate.sh". I downloaded the newest version and it works now to just say "rotate.sh"
Return to Gene's Home Page
Return to Gene's Random Unix Crap