Operating System - HP-UX
1825552 Members
2576 Online
109681 Solutions
New Discussion юеВ

Log file is emptied in var/adm/cron/log

 
SOLVED
Go to solution
ITSD-ACCS
Frequent Advisor

Log file is emptied in var/adm/cron/log

Hi,

Last week, I was doing some housekeeping on my own that empty the log file in /var/adm/cron. Unfortunately, no logs were generated since then. I checked with modes and ownership, it remains the same. How can I trigger the log files again ? Thanks. I was supposed to have a log generated in my cronjobs in every five minutes.
6 REPLIES 6
Patrick Chim
Trusted Contributor

Re: Log file is emptied in var/adm/cron/log

Hi,

Did you try to restart the cron daemon to 'kick start' the log file again ?

Regards,
Patrick
S.K. Chan
Honored Contributor
Solution

Re: Log file is emptied in var/adm/cron/log

Restarting the cron daemon should do it. Just make sure no current cron jobs are running before you restart it.
# /sbin/init.d/cron stop
# /sbin/init.d/cron start
Patrick Chim
Trusted Contributor

Re: Log file is emptied in var/adm/cron/log

Hi again,

After restarting the cron daemon, you should see something in the log file

! *** cron started *** pid = 1333 Mon Oct 14 18:09:55 EAT 2002

Regards,
Patrick
Darrell Allen
Honored Contributor

Re: Log file is emptied in var/adm/cron/log

Hi,

You've got the answer but I thought you may like a little more info.

/var/adm/cron/log is one of a number of system log files that are held open by a process. If you delete the file and re-create it, the process (in this case cron) is still trying to write to the file you deleted.

Before removing a file, you should use fuser or lsof on that file to see if something has it open. It's best to stop the processes holding the file open, do your house-keeping, then restart the process. In a pince, you could simply empty the file with ">/var/adm/cron/log".

One other note. Even though you re-created /var/adm/cron/log and its size was not increasing, the size of the old log was increasing. Remember, cron had the file open and was still writing to it. bdf would reflect this. du would not. Only when you stopped cron was the space released.

Generally, cron's log won't take enough space to matter but a busy log (such as /var/adm/syslog/syslog.log) will cause you problems.

Darrell
"What, Me Worry?" - Alfred E. Neuman (Mad Magazine)
ITSD-ACCS
Frequent Advisor

Re: Log file is emptied in var/adm/cron/log

Thank you Darrel. I emptied the file by using cat /dev/null > /var/adm/cron/log, I supposed this would be a safe way, but somehow, I needed to restart the cron again.
How can I empty a log file (system ones) safely ?

Thanks.
doug hosking
Esteemed Contributor

Re: Log file is emptied in var/adm/cron/log

Hopefully the vendor's documentation for the applications in question addresses this issue.

There unfortunately isn't a truly standard way to do this. It depends on which application is writing the log file and how that application was written. Stopping and restarting the application is one way, though you have to ask yourself what the consequences of that are for any particular process. (Will your system suffer any ill effects if that service isn't available for the time it takes to restart the program?)

In many cases, daemons are written such that sending them a SIGHUP signal will cause them to close and reopen their configuration files. For example, the manual page for
syslogd says:

"To make syslogd, re-read its configuration file, send it a HANGUP
signal:

kill -HUP `cat /var/run/syslog.pid`"

If the application in question supports this, it is usually the preferred way of handling the log file pruning problem, because the application doesn't terminate. It just gets notified that it needs to close and reopen the log file, which can usually be done in a fraction of a second without hurting any currently active operations. In this case you
could so something like:

mv logfile logfile.old
touch logfile
chown/chmod logfile as appropriate
kill -HUP

Verify that logfile is growing and that
logfile.old isn't, then archive, compress
or delete logfile.old as appropriate.

An alternative is to edit the boot scripts such that log files are pruned each time the system reboots. If something like a monthly reboot is not a problem for your system, you can automate the log file trimming. If that's not possible, the SIGHUP or stop/start approaches can be used.