logs


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers logs
# 1  
Old 10-28-2002
logs

can i include this command into my crontab file

> /var/adm/wtmp

to clear the contents on a regular basis ?
what about file permissions ?
# 2  
Old 10-28-2002
Just as a suggestion.

You could do the following..

## - Suitable comment here.
[mm] [hh] * * * rm /var/adm/wtmp ; touch /var/adm/wtmp ; chmod ??? /var/adm/wtmp


Makes it easier to read and even more so for newbie's who happen to be learning what is being run from cron.
# 3  
Old 10-28-2002
I would really recommend using ">" to truncate the file, rather than rm it, and have a different file (different inode) used for the next.

Depending on your Unix version, you may be able to use something like "logrotate". You'll probably need to install a version for your Unix, if one exists.
# 4  
Old 10-28-2002
I will admit, my suggestion is a long-winded approach.

I didn't know of the inode detail that LivinFree raised, thanks LivinFree.
# 5  
Old 10-29-2002
Aix 3.2

ancient i know but just one module still runs on this server , we have migrated to solaris 8 . I've never heard about logrotate livinfree... whats it abt

thanks
# 6  
Old 10-29-2002
Logrotate is typically distributed with Linux systems, but should be fairly simple to port over to others, since it's based (I believe) on perl. It's run via cron, and each time it runs, checks a set of config files that define archival, truncation, etc of log files.

If you just want to clear out that one periodically, it may just be easier to whip up a little script that cp's it to another file (in case you want to review it later), compresses the archive, and truncates that file.
# 7  
Old 10-29-2002
Quote:
Originally posted by LivinFree
If you just want to clear out that one periodically, it may just be easier to whip up a little script that cp's it to another file (in case you want to review it later), compresses the archive, and truncates that file.
Here is a little Perl script that I cooked up for automagically rotating logs of an application that sends the data to STDOUT and redirected to file.

Seems that in the above situation that you can't just cp the file as the inode pointer will still point at the new filename and keep on adding data (I simulated this on my FreeBSD system for a thread on another forum).

Code:
#!/usr/bin/perl

# Real cheezy attempt at piping STDOUT into a perl routine to automagically
# rotate logs. Idea inspired by cRock.
# Auswipe sez "Hey, no guarantees!"

my $lineCounter = 0;
my $logCount    = 1;

#open(LOGFILE, ">app.log.$logCount");

while (true) {
  if (($lineCounter > 1000) || ($lineCounter == 0)) {
    close(LOGFILE);
    open(LOGFILE, ">app.log.$logCount");
    $logCount++;
    $lineCounter = 1;
    # print STDERR "Rolled log to app.log.$logCount\n";
  };
  $logEntry = <STDIN>;
  $lineCounter++;
  print LOGFILE "$logEntry";
  #print STDERR "Made log entry.\n";
};

Usage:

Code:
./someapp | ./perl_buffer

Hmmm. After looking at my code I realize that I could just keep on incrementing $lineCounter and just use modular arithmatic to set the point to rotate the log. That'll teach me.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies

2. UNIX for Dummies Questions & Answers

Logs do not rotate

My problem: Both access and error logs do not rotate any more and get really large. They are located here: /srv/www/+vHost name here+/logs/ Configuration seems to be here: /etc/logrotate.conf => looks OK, including "size 10M" to avoid large files (/etc/logrotate.d => is empty) manually... (4 Replies)
Discussion started by: floko
4 Replies

3. HP-UX

HP-UX LOGS Files

hello, i just want to know logs files for these actions listed below : - User Account Creation - User Account Deletion - Failed and or Successful User Password Changes - Failed Login Activities for all User Users - System Reboot or and shutdown help appreciated... (1 Reply)
Discussion started by: Bolou
1 Replies

4. UNIX Desktop Questions & Answers

regarding logs

Hi , I am running an application on my windows and it logs are generated at /var/logs and for this i have to go this location and then do tail -f , Is there any command you can advise me so that when I execute this command at this location that logs get displayed fully and as the application... (3 Replies)
Discussion started by: KAREENA18
3 Replies

5. Shell Programming and Scripting

Grep yesterday logs from weblogic logs

Hi, I am trying to write a script which would go search and get the info from the logs based on yesterday timestamp and write yesterday logs in new file. The log file format is as follows: """"""""""""""""""""""""""... (3 Replies)
Discussion started by: harish.parker
3 Replies

6. HP-UX

how to trace the logs

Hi, Last day, In one of our unix boxes there was an issue wherein few of the directory structures were missing / got deleted. Is there any way by which we can find how it happened, I mean by going through syslog / which user had run what command? Thanks for your help (3 Replies)
Discussion started by: vivek_damodaran
3 Replies

7. Shell Programming and Scripting

filtering the logs

Hi, We are using rsync for syncing remote directories. It is working great along with detailed logs. As the script cron'd and most of the times there're no files to sync we are getting lot of unnecessary log entries and we need to filter them to show only the log entries for the files... (5 Replies)
Discussion started by: prvnrk
5 Replies

8. UNIX for Advanced & Expert Users

logs

Hy, I have a question I have a directory in a unix server, Some of my files have a diffrent access time, from the time i accessed them last, I think some one has copied it,it's not an important file,but none the less,it is my file,It mistakenly had a 777 permission( yes ,I know it is a noob's... (1 Reply)
Discussion started by: lordmod
1 Replies

9. Shell Programming and Scripting

Logs

Hey Guys, i am new into shell programming and i have to do one script which have to record all the commands entered by a specific user. Example of that, i have a system running on unix, several users are using this system, i have to create like a databse which will record every user entered that... (5 Replies)
Discussion started by: charbel
5 Replies

10. UNIX Desktop Questions & Answers

Logs

hi My name is Juan I dont can clear wtmp and similiar files how i do it? thanks (4 Replies)
Discussion started by: jtapia
4 Replies
Login or Register to Ask a Question