1835267 Members
2612 Online
110078 Solutions
New Discussion

Re: log files

 
SOLVED
Go to solution
Ali Imran Abbas
Regular Advisor

log files

I need some information about the log files. If they grow big, how can you truncate them. I had a cron log file in /var/adm/cron/log. I coppied it to oldlog and removed the original one. Then created another log file with the same name and sets of permissions, but cron is not writing to it. Can any one help me in this regard.

Regards,

Ali
8 REPLIES 8
Pete Randall
Outstanding Contributor
Solution

Re: log files

You need to stop and restart your cron process:

/sbin/init.d/cron stop
/sbin/init.d/cron start

In the future, I would suggest using SAM to trim your log files.


Pete

Pete
Torsten.
Acclaimed Contributor

Re: log files

Use

sam
-> routine tasks
-> system log files
(select the log)
-> Actions -> trim


but there are so many other ways too ...


BUT never delete the file!

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Ali Imran Abbas
Regular Advisor

Re: log files

HEy ,
I tried doing this, but it gives me an error.

usunx08:# cron stop
usunx08:# ! cron is already running Thu Jan 24 11:35:31 EST 2008
! ******* CRON ABORTED ******** Thu Jan 24 11:35:31 EST 2008

usunx08:#

Any suggestion in this regard?
TTr
Honored Contributor

Re: log files

The log file that you removed was in "open" state by the cron daemon. You must NEVER remove an open file. Almost each and every time, removing an open file will hung the process that has that file open.

In your case you must restart cron.

In general before removing a file you check it using the "fuser" command. The fuser command will show you if the file is open and which process has it open.

Some daemons will listen to a HUP signal to reread their config environment. These are syslogd, crond etc.

The standard method for rolling a syslog log file is

1) mv syslog.log syslog.log-old (the move command does not impact an open file. The new name is still open by the same process and still being logged on)
2) kill -HUP
A new syslog.log will be created.

Using this method, there is no interuption in the daemon coverage. If you restart a daemon you will have a 3-5 seconds of no-daemon service. It depends how critical you server environment is.
Torsten.
Acclaimed Contributor

Re: log files

/sbin/init.d/cron stop

/sbin/init.d/cron start

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!   
Pete Randall
Outstanding Contributor

Re: log files

Ali,

Not sure why you had problems. This works for me:

# /sbin/init.d/cron stop
cron stopped
# /sbin/init.d/cron start
cron started


Pete

Pete
James R. Ferguson
Acclaimed Contributor

Re: log files

Hi:

Using the '/sbin/init.d/cron' script to stop and (re)start your cron daemon has the advantage that the current '/var/adm/cron/log' is moved to '/var/adm/cron/OLDlog' and the 'cron' daemon restarted when the script's argument is "start". You can then compress or remove the 'OLDlog' as you see fit.

There is NO PROBLEM with removing an open file! In fact, it is a common technique to open a temporary file and immediately 'unlink()' it. A file's disk space remains inuse until the last process referencing it terminates and the in-use count decrements to zero. Moving a file with 'mv' retains the inode number of a file but allows its name to be changed. Thus the association between a process and the inode remains and in the case of log files, the logging continues.

Regards!

...JRF...
Robert-Jan Goossens
Honored Contributor

Re: log files

Hi Ali,

Are you sure you are on a HPUX box?

usunx08

If this a sun try

# /etc/init.d/cron stop
# /etc/init.d/cron start

Regards,
Robert-Jan