LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   cron problem (https://www.linuxquestions.org/questions/linux-newbie-8/cron-problem-232505/)

haldara 09-19-2004 10:31 AM

cron problem
 
Hi guys:


So I decided to add an entry to my crontab for root that would automatically delete the cron log in /var/log/cron every month and just add a timestamp to let me know that it had been done. However, even with the correct perms, for some reason, the log file is no longer being written to. Here is my crontab entry for root:

52 4 19 1-12 * rm -rf /var/log/cron ; touch /var/log/cron; echo "Refreshed Cronlog: " > /var/log/cron; date >> /var/log/cron;

Here are the permissions:
-rw-rw-rw- 1 root root .... /var/log/cron

Any thoughts?
- ADH

druuna 09-19-2004 10:46 AM

Hi,

You are deleting an 'open file'.

/var/log/cron is an open file, which means that your logdaemon (probably syslogd) keeps this file open to write output too.

When you delete the file and create it again, the 'pipe' from syslogd to /var/log/cron points to the deleted /var/log/cron and not to the newly created /var/log/cron (there's a bit more going on, but I'm keeping it simple).

So, instead of using:
rm -rf /var/log/cron ; touch /var/log/cron
use:
> /var/log/cron

This will empty /var/log/cron without breaking the pipe.

Hope this clears things up a bit.

haldara 09-19-2004 11:00 AM

Awesome, that makes alot of sense.

Since I already broke the pipe, is there anyway to recreate the pipe from syslogd to this new /var/log/crond without rebooting?

Thanks!

druuna 09-19-2004 11:42 AM

You need to restart syslogd.

You do not tell what distro you are using, the file could be in /etc/rc.d/init.d or in /etc/init.d and the name should reflect syslog.

To actually restart do something like this (example is from my machine):

$ /etc/rc.d/init.d/sysklogd restart

Another, maybe easier way is to look for the syslog process in the process list (ps -ef | grep syslog) and give a SIGHUP signal to the pid belonging to syslog.

$ ps -ef | grep [s]yslog
$ kill -SIGHUP <pid>


Hope this helps.


All times are GMT -5. The time now is 06:25 AM.