PDA

View Full Version : Issue regarding Daily Rotating Log file



Santosh_2411
24-Jul-2015, 07:44
Hello All,

I have to Rotate one of my log file (test_cron.log) which is under /root/ on daily basis , so for that i have made one new file in under /etc/logrotate.d/soc_logs.
also added entry in crontab as : */1 * * * * /usr/sbin/logrotate /etc/logrotate.d/soc_logs
But it does not rotate daily.
and write code as follows.

/root/test_cron.log
{
compress
daily
size 20k
rotate 7
dateext
create 0600 root root

}

Also i want 7 days backup of that log file and if file size increased by say for example 20k then also it must be make new file with date extension.

Thanks in advance..
Santosh..

ab
24-Jul-2015, 11:40
On 07/24/2015 12:54 AM, Santosh 2411 wrote:
>
> I have to Rotate one of my log file (test_cron.log) which is under
> /root/ on daily basis , so for that i have made one new file in under
> /etc/logrotate.d/soc_logs.
> also added entry in crontab as : */1 * * * * /usr/sbin/logrotate
> /etc/logrotate.d/soc_logs
> But it does not rotate daily.
> and write code as follows.
>
> /root/test_cron.log
> {
> compress
> daily
> size 20k
> rotate 7
> dateext
> create 0600 root root
>
> }

Is the size of the to-be-rotated file at least 20k, as you have defined as
a requirement above? If not, no rotation will happen unless you add
'ifempty'.

What happens if you call the command directly and add the --verbose switch
so you can see evaluation as it happens? Post back here and we should be
able to help analyze it.

Also, your cron entry is redundant; */1 is the same as *, so just go with
* unless you have a great reason to do otherwise. Also, be sure your cron
job is running as 'root'; if you are properly using 'crontab -e' to setup
the crontab entry, and are doing so as a non-root user, then that would
impact this of course since a non-root user's cron job would not have
rights to do anything in /root by default.

Finally, you should probably setup this logrotate definition under
/etc/logrotate.d along with other files. This way you do not need a
separate cron job. If you really want its own call via cron, then put
your cron definition under /etc/cron.daily instead, rather than having
your own cron job setup.

> Also i want 7 days backup of that log file and if file size increased by
> say for example 20k then also it must be make new file with date
> extension.
>
> Thanks in advance..
> Santosh..
>
>

--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...

Santosh_2411
27-Jul-2015, 08:50
On 07/24/2015 12:54 AM, Santosh 2411 wrote:
>
> I have to Rotate one of my log file (test_cron.log) which is under
> /root/ on daily basis , so for that i have made one new file in under
> /etc/logrotate.d/soc_logs.
> also added entry in crontab as : */1 * * * * /usr/sbin/logrotate
> /etc/logrotate.d/soc_logs
> But it does not rotate daily.
> and write code as follows.
>
> /root/test_cron.log
> {
> compress
> daily
> size 20k
> rotate 7
> dateext
> create 0600 root root
>
> }

Is the size of the to-be-rotated file at least 20k, as you have defined as
a requirement above? If not, no rotation will happen unless you add
'ifempty'.

What happens if you call the command directly and add the --verbose switch
so you can see evaluation as it happens? Post back here and we should be
able to help analyze it.

Also, your cron entry is redundant; */1 is the same as *, so just go with
* unless you have a great reason to do otherwise. Also, be sure your cron
job is running as 'root'; if you are properly using 'crontab -e' to setup
the crontab entry, and are doing so as a non-root user, then that would
impact this of course since a non-root user's cron job would not have
rights to do anything in /root by default.

Finally, you should probably setup this logrotate definition under
/etc/logrotate.d along with other files. This way you do not need a
separate cron job. If you really want its own call via cron, then put
your cron definition under /etc/cron.daily instead, rather than having
your own cron job setup.

> Also i want 7 days backup of that log file and if file size increased by
> say for example 20k then also it must be make new file with date
> extension.
>
> Thanks in advance..
> Santosh..
>
>

--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...


************************************************** *****

Thanks ab.. :-)

as per your suggestion, its working now..

ab
27-Jul-2015, 13:20
Thank-you for posting back your results as they will likely help others.

--
Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below...