Issue regarding Daily Rotating Log file

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…

On 07/24/2015 12:54 AM, Santosh 2411 wrote:[color=blue]

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

}[/color]

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.
[color=blue]

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…

[/color]


Good luck.

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

[QUOTE=ab;28864]On 07/24/2015 12:54 AM, Santosh 2411 wrote:[color=blue]

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

}[/color]

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.
[color=blue]

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…

[/color]


Good luck.

If you find this post helpful and are logged into the web interface,
show your appreciation and click on the star below…[/QUOTE]


Thanks ab… :slight_smile:

as per your suggestion, its working now…

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…