Is it possible not to specify a directory for the file location and use the...
Implementation of logrotate utility for Windows Platform
Status: Beta
Brought to you by:
kennethsalter
Hi, is it possible not to specify a directory for the file location and use the current folder where logrotate.exe is located? It would be nice to just copy logrotate.exe and logrotate.conf into a folder and rotate the logs in that folder... That way makes it really easy to add something similar to the following command - logrotate.exe -s logrotate.status logrotate.conf -v - to the end of a batch file that is already running a job and not have to add another scheduled task or update a central config file.
I tried a few things similar to the example below (..*.log, ~*.log, * .log) but couldn't get any of them to work. Does anyone know if this is possible and I just couldn't get the right syntax? If not maybe a suggestion for a later version?
*.log {
rotate 7
daily
nocompress
}
Thanks in advance for your help, Dom
I think (I haven't looked at the code) that it needs to see a \ in the path. So perhaps something like ..*.log? I'm also not sure if the logrotate command from the Linux world supports what you want, which is why it isn't in this one. That isn't to say it can't be done, of course.
You were right about the code, and it did work, I just needed to think of the the proper directory notation - more details below for anyone who finds it useful and maybe a nice one to have in the documentation or an example as you would then be able to do what I mentioned in my question (add it to the end of an existing batchfile that is already scheduled).
The short version - use something like .\*.log {
rotate 5
daily
}
Long version - as Ken mentioned, it does seem to look for a \ in the code to pick up that it's a folder, at least if the latest version on GitHub is anything to go by (there is a later version in this discussion forum but without the source code).
private static void ProcessConfileFileSection
..
..
// if we see a ", then this is either starting or ending a file path with spaces
case '\"':
if (bQuotedPath == false)
bQuotedPath = true;
else
bQuotedPath = false;
split += starting_line[i];
break;
So without wanting to change the code, I played around with the cd command in DOS to check what would essentially change directory but really leave you where you were - cd .\ worked and so did dir .\*.log so I tried that in the .conf file and it all worked prefectly (sample output at the bottom of this post, with the additional -s parameter to keep the status file in the current folder)
ps if anyone is wondering about the missing backslashes in my initial question, I didn't realise you needed 2 \ to escape it, otherwise the sourceforge editor removes it (thinks it is an italic marker).
Hope this helps someone else, Dom
C:\Logrotate>logrotate.exe -v test.conf -s logrotate.status
logrotate: logrotate 0.0.0.16 - Copyright (C) 2012-2013 Ken Salter
logrotate: Verbose option set to true
logrotate: test.conf Adding to config files to process
logrotate: Setting alternate state file to logrotate.status
logrotate: Parsing configuration file test.conf
logrotate: Processing new section
logrotate: Processing .\*.log
logrotate: Processing C:\Logrotate\test.log
logrotate: Processing C:\Logrotate\test_again.log
logrotate: Rotating file C:\Logrotate\test.log
logrotate: Renaming C:\Logrotate\test.log to C:\Logrotate\test.log.1
logrotate: Updating rotation date in status file
logrotate: Rotating file C:\Logrotate\test_again.log
logrotate: Renaming C:\Logrotate\test_again.log to C:\Logrotate\test_again.log.1
logrotate: Updating rotation date in status file
Last edit: Dom 2015-12-07