rc-list - mailing list for the rc(1) shell
 help / color / mirror / Atom feed
* a quick hack
@ 1992-06-17 15:01 Brendan Kehoe
  0 siblings, 0 replies; only message in thread
From: Brendan Kehoe @ 1992-06-17 15:01 UTC (permalink / raw)
  To: rc mailing list


I just threw this together, and thought it might be useful to others.
It's the equivalent of /usr/lib/newsyslog, but adds a little more
power and pep to it.  Comments on style welcome.

--
#!/bin/rc
# Rotate the logs like /usr/lib/newsyslog, but $compress 'em.  (The times
# I actually check the old logs are one in a googleplex.)  If you'd rather
# not compress them, just change compress to `true'.

logs=(/var/adm/messages /var/log/syslog)
compress=freeze ; ext=F

fn rotate {
  file=$1 ; shift
  while (! ~ $#* 1) {
   { ~ ($file.$2^*) $file.$2^'*' ||
     { mv -f $file.^($2 $1)^.$ext ||
       { mv -f $file^(.$2 .$1) && $compress $file.$1 }
	# we could do:  eval ('mv -f $file.$2 ' '&& $compress ')^$file.1
     }} >[2] /dev/null
   shift
  }
}

umask 22 # create the new log with mode 644

for (log in $logs) {
  test -s $log && {
     rotate $log 7 6 5 4 3 2 1 0
     mv -f $file $file.0 && $compress $file.0
     > $log
  }
}
exit 0

--
Brendan Kehoe, Sun Network Manager                      brendan@cs.widener.edu
Widener University                                                 Chester, PA
    In action-oriented shows, TV cops fire their guns in almost every episode;
       in Chicago, the average police officer fires a gun once every 27 years.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~1992-06-17 15:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1992-06-17 15:01 a quick hack Brendan Kehoe

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).