From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII X-Google-Thread: fa528,8f76dbbdaf6ffd7a X-Google-Attributes: gidfa528,public X-Google-ArrivalTime: 2001-09-11 23:32:23 PST Path: archiver1.google.com!newsfeed.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!t-online.de!news-ge.switch.ch!news-zh.switch.ch!newsfeed-zh.ip-plus.net!news.ip-plus.net!fwsrva.bfi.admin.ch!131.102.101.224 From: Jonas Furrer Newsgroups: comp.unix.tru64 Subject: Re: logrotate? Date: Wed, 12 Sep 2001 08:33:19 +0200 Organization: RealStuff Informatik AG Message-ID: <3B9F01AF.DCA72D79@realstuff.ch> References: <0rjrptka1jvsapv2nk1b2170ihec87s58c@4ax.com> Reply-To: jonas.furrer@realstuff.ch NNTP-Posting-Host: fwigk1.admin.ch Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: rex.ip-plus.net 1000276338 14124 193.5.216.70 (12 Sep 2001 06:32:18 GMT) X-Complaints-To: abuse@ip-plus.net NNTP-Posting-Date: Wed, 12 Sep 2001 06:32:18 +0000 (UTC) X-Mailer: Mozilla 4.75 [en] (Windows NT 5.0; U) X-Accept-Language: en X-Original-NNTP-Posting-Host: 131.102.101.224 Xref: archiver1.google.com comp.unix.tru64:4839 "Axel K�ster" wrote: > Hello to all, > > does anyone know of a logrotate tool running on True64 (4.0..), preferrable a > binary? > > Thanks in advance > > Axel Hi Axel Maybe this Perl-Script helps. It is designed to use with Tru64 V4 / V5 Unix, that meens CDSL's are handeld hopefully correctly. No Warranty. Bye Jonas -----------------------------8x ----------x8 -------------------------------- #!/bin/perl -w # # $Id: rotate_log.pl,v 1.3 2001/07/02 09:41:54 t750t Exp $ # # ------------------------------------------------------------------------------ # Filename: rotate_log.pl # # Usage: see subroutine 'print_usage' # # Author: Jonas Furrer, RealStuff Informatik AG (http://www.realstuff.ch) # # Abstract: Rotates Files. /var/adm/messages and /var/adm/binary.errlog # are rotated only if they contain a boot record. # CDSL-Links are handeld correctly. Compression can be enabled. # # Requirements: - Digital UNIX 3.2 or higher # - Perl 5.004 or higher # # Output-files: rotated files # # ------------------------------------------------------------------------------ # Edition history: # # 13.06.2001 jfu Initial version # 02.07.2001 jfu Bug-Fix: dealing context-dependent symbolic link use vars qw($opt_d $opt_c $opt_v $opt_m); use Getopt::Std; use File::stat qw(:FIELDS); sub print_usage { print "\nUsage: rotate_log.pl [-dm] [-v [count]] [-c method] [-f input file] filename\n"; print " -d\t\t -> debug\n"; print " -m\t\t -> sends no mail\n"; print " -c method\t -> compress\n"; print " Z\t = Unix standard compression\n"; print " gz\t = gzip compression\n"; print " -v count\t -> versions\n"; print " -f input file\t -> File containing files to rotate\n"; print " filenames\t -> Files to rotates, wildcards allowed\n"; print "\n"; exit; } # ----------------------------- Global declarations ---------------------------- chomp(($OSVERSION) = (`uname -r | cut -d. -f1`)); # ----------------------------- Parse Command line ----------------------------- if ( ! getopts("dmc:f:v:")) # d/m = Boolean; { print_usage; } if ( defined ($opt_d) ) {$DEBUG = "TRUE";} else {$DEBUG = "FALSE";} if ( defined ($opt_m) ) {$NOMAIL = "TRUE";} else {$NOMAIL = "FALSE";} if ( defined ($opt_v) ) {$VERSIONS = $opt_v;} else {$VERSIONS = 1;} # --- Compression --- if ( defined ($opt_c) ) { $COMPRESS = "TRUE"; $EXT=".".$opt_c; if ($opt_c =~ /Z/ ) { $COMPRESS_CMD = "/usr/bin/compress"; } elsif ( $opt_c =~ /gz/ ) { $COMPRESS_CMD = "/usr/bin/gzip";} else { print "Unknown compression method\n"; print_usage; exit;} } else { $COMPRESS = "FALSE";$EXT=""; } # --- Files to rotate --- if ( defined ($opt_f) ) { open(FH, $opt_f) or die("Can't open $opt_f: $!\n"); while (defined ($line = )) { chomp($line); if ( $DEBUG =~ /TRUE/i ) { print "File list: $line\n";} push(@FILES,$line); } close(FH); } if ( defined ($ARGV[0])) { push(@FILES , @ARGV); } else { if ( ! defined ($opt_f)) { print "No Files to rotate\n"; print_usage; exit; } } # --- Print Debug info --- if ( $DEBUG =~ /TRUE/i ) { print "We are a $OSVERSION system\n"; print "\nOption d\t= $DEBUG\n"; print "Option m\t= $NOMAIL\n"; print "Option c\t= $COMPRESS \t\tMethod = $EXT\n"; print "Option v\t= $VERSIONS\n"; print "Count Files\t= $#ARGV\n"; print "File list\t= @FILES\n"; } # ---------------------------------- Sub Routines ------------------------------ sub mkcdsl { my $file = shift; chomp($tmp_file = `basename $file`); `/usr/sbin/mkcdsl -f $tmp_file`; } sub print_detail_info { $msg = "-> /var/adm/binary.errlog contains no startup message.\n"; $msg .= "-> binary.errlog and messages will not be switched.\n\n"; $msg .= "Output of 'ls -al /var/adm/binary.errlog*':\n"; $msg .= `/sbin/ls -al /var/adm/binary.errlog*`."\n"; $msg .= "Output of 'ls -al /var/adm/messages*:\n"; $msg .= `/sbin/ls -al /var/adm/messages*`."\n"; $msg .= "Output of 'df -k /var/adm':\n"; $msg .= `/sbin/df -k /var/adm`."\n"; $msg .= "Output of 'uptime':\n"; $msg .= `/usr/bin/uptime`."\n"; if ( $NOMAIL =~ /TRUE/i ) { print $msg; } else { `echo $msg | /usr/bin/mailx -s "No log switch" root`; } } sub rotate { my $file = shift; my $count= shift; if ( $DEBUG =~ /TRUE/i ) { print "\n\$file = $file\n" ;} stat($file) or die "No $file: $!"; # gets all inode informations # --- Rotate from 1 to n --- for ($i=$count-1; $i > 0; $i--) { $ii = $i+1; if ( -e "$file.$i$EXT" ) { if ( $DEBUG =~ /TRUE/i ) { print "mv $file.$i$EXT $file.$ii$EXT\n";} `mv $file.$i$EXT $file.$ii$EXT`; `chown $st_uid.$st_gid $file.$ii$EXT`; if ($OSVERSION =~ /V5/) { mkcdsl("$file.$ii$EXT"); } } } if ( $DEBUG =~ /TRUE/i ) { print "cp $file $file.1\n";} # --- Rotate actual file --- `cp $file $file.1`; `cp /dev/null $file`; if ($OSVERSION =~ /V5/) { mkcdsl("$file.1"); } # --- Compress if desired --- if ( $COMPRESS =~ /TRUE/i ) { if ( -s "$file.1" ) { `$COMPRESS_CMD -f $file.1`; } else { `mv $file.1 $file.1$EXT`; } # Zero-Files would not compressed } `chown $st_uid.$st_gid $file.1$EXT`; } # ------------------------ MAIN-LOOP: Read in files to rotate ------------------ if ( defined( $FILES[0] )) { foreach $file (@FILES) { if ( -e $file ) { if ( -l $file ) { chomp($tmp_dir = `dirname $file`); chdir($tmp_dir); # --- due to relativ referenced links if ( $DEBUG =~ /TRUE/i ) { print "Changing Directory to $tmp_dir \n";} chomp($line = `ls -l $file`); ($file = $line) =~ (s/.*->\s+(.*)$/$1/); } } else { print "File : $file does not exist\n"; exit; } if (( $file =~ /binary.errlog$/ ) || ($file =~ /messages$/)) { $startup_count = `/usr/sbin/uerf -R | /sbin/grep STARTUP | /usr/bin/wc -l` ; if ( $startup_count == 0 ) { print_detail_info; exit; } } rotate("$file", $VERSIONS); } }