# Issue regarding Daily Rotating Log file

**URL:** <https://forums.suse.com/t/issue-regarding-daily-rotating-log-file/27270>\
**Category:** SLES Configure-Administer\
**Created:** [July 24, 2015, 9:44am UTC](https://forums.suse.com/t/issue-regarding-daily-rotating-log-file/27270 "2015-07-24T09:44:57Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Santosh\_2411](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Santosh\_2411](https://forums.suse.com/u/Santosh_2411)\
**Post date:** [July 24, 2015, 9:44am UTC](https://forums.suse.com/t/issue-regarding-daily-rotating-log-file/27270/1 "2015-07-24T09:44:57Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![ab1](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@ab1](https://forums.suse.com/u/ab1)\
**Post date:** [July 24, 2015, 1:40pm UTC](https://forums.suse.com/t/issue-regarding-daily-rotating-log-file/27270/2 "2015-07-24T13:40:12Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![Santosh\_2411](https://avatars.discourse-cdn.com/v4/letter/s/e0b2c6/32.png) [@Santosh\_2411](https://forums.suse.com/u/Santosh_2411)\
**Post date:** [July 27, 2015, 10:50am UTC](https://forums.suse.com/t/issue-regarding-daily-rotating-log-file/27270/3 "2015-07-27T10:50:31Z")

</div>

[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… 🙂

as per your suggestion, its working now…

---

<div class="post-metadata">

**Author:** ![ab1](https://avatars.discourse-cdn.com/v4/letter/a/d2c977/32.png) [@ab1](https://forums.suse.com/u/ab1)\
**Post date:** [July 27, 2015, 3:20pm UTC](https://forums.suse.com/t/issue-regarding-daily-rotating-log-file/27270/4 "2015-07-27T15:20:59Z")

</div>

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…
