homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

Logrotate update
so I can use dateext

 8:22 pm on Feb 1, 2010 (gmt 0)

I asked this already in Apache - wrong spot obviously.

I want to update my VPS so I can use dateext.

Is there any resource online that describes this step by step?

I do have server background (windows) and play with Apache a little. Linux is totally unknown to me.
I understand that something needs to be compiled, and that there are some steps for installation.
I don't even know what version of Linux I have on the VPS. The hosting provider is WestHost.
I'm fine with command prompt related actions.




 7:47 pm on Feb 3, 2010 (gmt 0)

Well, I give up on looking for this. Plus, I'm not even sure if I can do it myself since this is VPS with limited access to the OS. That's what I think, because when I use Putty, I get into the root of my site, not the root of VPS like when I browse it via FTP client.

Anyway, I learned about simply renaming a file with postrotate command. I have two options:

/bin/mv /var/log/httpd/access_log.1.gz /var/log/httpd/access_log-`/bin/date +"%Y-%m-%d"`
/bin/cp /var/log/httpd/access_log.1.gz /var/log/httpd/access_log-`/bin/date +"%Y-%m-%d"`

First one moves file (deletes original), second just copies.

I have two problems:

1. It does not work from logrotate.conf
2. It works if I run the comman manually from Putty, but loses the .gz extension. How do I tell it to keep GZ extension?

About 1., here is what I have in logrotate.conf:


/var/log/httpd/access_log {
rotate 365
#/bin/mv /var/log/httpd/access_log.1.gz /var/log/httpd/access_log-`/bin/date +"%Y-%m-%d"`
/bin/cp /var/log/httpd/access_log.1.gz /var/log/httpd/access_log-`/bin/date +"%Y-%m-%d"`

/var/log/httpd/agent_log /var/log/httpd/error_log /var/log/httpd/referer_log /var/log/httpd/ssl_request_log /var/log/httpd/ssl_engine_log {

/var/log/maillog {

include /etc/logrotate.d

Does postrotate happen after gzip does the job or I'm missing something here?



 12:44 am on Feb 4, 2010 (gmt 0)

Keeping the .gz extension:

/bin/mv /var/log/httpd/access_log.1.gz /var/log/httpd/access_log-`/bin/date +"%Y-%m-%d"`.gz
/bin/cp /var/log/httpd/access_log.1.gz /var/log/httpd/access_log-`/bin/date +"%Y-%m-%d"`.gz


 6:28 am on Feb 4, 2010 (gmt 0)

Keeping the .gz extension

I thought it should be somewhere at the end, but I was scared of such simplicity, so I haven't even try.

BTW, where should I look for errors on Linux? It's CentOS in this case.



 10:50 am on Feb 4, 2010 (gmt 0)

Urghhhh... yeah 2:30 AM

When I figured how to force logrotate to run, I saw bunch of errors in my Putty, line by line.

As it turns in 99% of the IT related troubleshooting, it was something very simple that have made my logrotate.conf not to work... very simple but not really mentioned in places about logrotate... or I haven't been reading well...

Do not use notepad or any other Windows/DOS related editor as it converts UNIX end of line (LR) to DOS end of line (CR LR). Aarghhh...
When I came across information about this, I turned end of linbe option in Notepad++, and I saw the damned CR LR.

If you have your file already in DOS mode, use dos2unix command to convert it (back) to UNIX (in your Putty or whatever you use).

Anyway, once I figured that, and converted end lines to the proper ones (UNIX), and I run the logrotate again, it worked, except one thing - compress at the right time.

In short, when I enter my line about renaming the Gziped file into one with the date stamp, it claims the file is not there. If I rename not-Gziped file, it's there, but zip does not happen at all.

I figured that compress happens after the postrotate, however that is being determined by the system.

I know that my alternative is to run a separate cron job after all the logrotate is done, and I don't mind, but it just looked nice and clean to do everything within the logrotate.

Can anyone shed some light onto if it's possible to run a command after the log file has been zipped? Is that compress really the very last thing that happens when logrotate runs?
I tried putting my rename command outside of everything (at the bottom) with no luck.



 9:45 pm on Feb 4, 2010 (gmt 0)

What OS is your system running. Also what do you want the name to look like?

If you do not want compression, you can comment out "compress" in your logrotate.conf. Or you can add nocompress to specific services.


 6:16 pm on Feb 5, 2010 (gmt 0)

I went with adding a cron job. But... It complains about ` character.

If I do it from command prompt (in Putty), it works fine.

The whole line is:

5 1 * * * /bin/cp /var/log/httpd/access_log.1.gz /var/log/httpd/access_log-`/bin/date +"%Y-%m-%d"`.gz

What's wrong with it?


 1:26 am on Feb 6, 2010 (gmt 0)

Did you store this line directly in the /etc/crontab file? In that case with a default CentOS configuration you need to add the username under which the process will run directly after the time parameters. i.e.:

5 1 * * * root /bin/cp /var/log/httpd/access_log.1.gz /var/log/httpd/access_log-`/bin/date +"%Y-%m-%d"`.gz


 5:00 am on Feb 6, 2010 (gmt 0)

There were already four lines in crontab, none with root, but I understand you say I should use root because of date command.

I changed it to double quotes. I'm curious to see if that works.
If not, I'll put root as per your suggestion.

I wonder about testing.

If I put a cron job to run every two minutes:

2 * * * * /directive

Does that get picked right away, or I have to wait for some time? Is cron daemon immediately aware of changes (when you save something under crontab), and therefore executes stuff as per schedule right away?

I feel dumb to wait 24 hours in order to see if stuff runs properly.



 6:37 am on Feb 6, 2010 (gmt 0)


I tried it and it said: "bad ` sign"

What's up with that ` sign?


 12:01 am on Feb 7, 2010 (gmt 0)

The devil is in the details. There are several versions of cron and some need a username to know under which privileges the command must be run while other versions run the command as root and rely on an su statement to set the user. You mentioned CentOS and the default cron version (Vixie cron) uses the syntax I mentioned. But it seems that your host installed a different cron version.

2 * * * * /directive

Some versions of cron (including Vixie cron) check every minute if the crontab file has changed. If this is the case, they automatically load the newest settings. On other versions you need to send the hang-up signal to the cron daemon. You can send the hang-up signal to the cron daemon with:

pkill -SIGHUP crond

Furthermore, your example will not run every two minutes, but two minutes after every hour:

0:02, 1:02, 2:02 etc.

To run a command every two minutes you need to provide all the possibilities:

0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58 * * * * /directive

or with some cron versions:

0-59/2 * * * * /directive


 1:22 am on Feb 7, 2010 (gmt 0)

your example will not run every two minutes

Oh foolish me...

Thanks for hints. Well, I guess it's the time for their forum. I mean, I could do it earlier, but then, there would be no sweat feeling of going crazy at after midnight time, and not to experience all that testing nervousness.

I'll come back with the details, if I get any.

Thanks again.


 4:06 am on Feb 7, 2010 (gmt 0)

So it's happy end.

The way how I made it work was to schedule a cron job just like:

5 1 * * * /path/text-file

where the "text-file" was really a text file having my full command with not so loved (by cron) grave accents, and UNIX end of line at the end (LR).

That was it, incredible how simple it sounds.

Oh yeah, I did put the execute attribute onto the text-file itself.

It is just unbelievable how much all of those (open source) OSs differ, including Cron for which I still don't know which version (or variation) it is. The guy on call did not know either, I have to check back on Monday (if I want).

I guess one is better to do any kind of scripting and/or programming in the language of choice, and then simply call it from the crontab which I guess has been created for that purpose, rather then to run stuff straight from within it.

Thanks for valuable inputs.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved