LSTSRV-L Archives

LISTSERV Site Administrators' Forum

LSTSRV-L

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Topic: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
"Wayne T. Smith" <[log in to unmask]>
Mon, 1 May 2000 16:18:14 -0400
text/plain (167 lines)
Anthony Del Rosso <[log in to unmask]> wrote, in part..
>Can someone give us an idea, or is their a known script to rotate the
listserv.log file nightly in a UNIX environment.

I'm a newbie *nix person, so real techies would probably cring at this,
but I use the following bash script with LISTSERV on Linux. No warrantee;
You know more *nix than me!

It requires that you remove the "mv" to "listserv.log.OLD" and append to
"listserv.log" in the "go" script, and that you call it (cron) whenever.
I use it at end of each day. Note: stuff in logs with any date probably
has LISTSERV output from previous day(s).

Here's the "go" code segment changed (segment ends with #####)

#
if [ "$is_bg" = "bg" -o "$is_bg" = "background" ]
then
    if [ -s listserv.log ]
    then
#
# 2000-04-26 [log in to unmask] (omit using .OLD on listserv.log)
#        mv listserv.log listserv.log.OLD
    echo "WTS End.."
    fi
    echo "> Starting LISTSERV as a background process"
#
# 2000-04-26 [log in to unmask] (append, not create, current listserv.log)
    lsvlog="2>&1 >>listserv.log"
    if [ "$notty" != "Y" ]
    then
        lsvdet="&"
    fi
fi
#
##### (end of "go" changed segment)


Function:  Break out logs.  If run daily, it keeps the most recent
"n" days of logs.

Code:

#!/bin/bash
# roll-listserv-log.bash -- 2000-04-27 -- [log in to unmask]   Wayne T. Smith
#
# This bash script
#
#    (0) (verify we are "listserv")
#    (1) stops listserv
#    (2) appends log from listserv.log to fileid including current date
#        saved log will be called listserv-yyyy-mm-dd.log
#    (3) discard listserv.log file
#    (4) restarts listserv
#    (5) discard old logs (keep n of them)
#
#
# Note: Modify the listserv "go" script to bypass it's listserv.log.OLD
#       stuff.  Must retrofit that mod when upgrading listserv code.
#
#
# (Maybe someday FTP someplace? Maybe not)
#
# - - - - - - - - - - - - - - - - - - - - - - - - - -

lsvroot="/home/listserv"        # code/listserv root directory
logroot="/home/listserv"        # listserv.log directory
logfile="listserv.log"          # fileid of "console log"

keep_n=14                       # number of (days) logs to keep
                                # ("days" if this script run every day)

exit_status=0                   # final exit status

#
# Only run if we are "listserv"
#

if   `whoami|tr  a-z   A-Z ` != "LISTSERV"  ; then
   echo "$0 error; must be run from the 'listserv' userid, not" `whoami`"."
   exit 1
   fi
cd $lsvroot
if   $? != 0  ; then
   exit_status=$?
   echo "$0 error $exit_status; must be able to 'cd' to $lsvroot."
   exit $exit_status
   fi
cd $logroot
if   $? != 0  ; then
   exit_status=$?
   echo "$0 error $exit_status; must be able to 'cd' to $logroot."
   exit $exit_status
   fi

#
# (1) stop listserv if it is running
#

killed=0
for proc in `ps -C lsv|grep lsv|awk '{print $1}'`
do
   kill $proc 2>/dev/null    # ignore errors (2nd kill may fail)
   killed=1
   done

if   $killed  ; then
   sleep 5 s
else
   echo "We note that listserv is not currently running."
   fi

#
# (2) append log from listserv.log to fileid including current date
# (3) and discard listserv.log if copy of file worked.
#

if   -s $logfile  ; then
   outfile="listserv"`date +-%Y-%m-%d`".log"
   cat $logfile >> $outfile
   if   $? = 0  ; then
      rm $logfile
      if   $? != 0  ; then
         exit_status=$?
         echo "$0 error $? erasing $logfile after copy to $outfile."
         #                      # don't exit so we can restart server
         fi
      cp /dev/null $logfile     # create a null file
      chmod 640    $logfile     # no public read permission
   else
      exit_status=$?
      echo "$0 error $exit_status appending $logfile to $outfile."
      # exit 1                  # don't exit so we can restart server
      fi
   fi

#
# (4) restarts listserv
#

cd $lsvroot
./go bg
if   $? != 0  ; then
   exit_status=$?
   echo "$0 error $exit_status; listserv 'go bg' may have failed."
   fi

#
#    (5) discard old logs (keep n of them)
#

cd $logroot
i_th=0
for fileid in `ls -1 listserv-*.log 2>/dev/null|sort -rf|awk '{print $1}'`
do
   let i_th=i_th+1
   if   $i_th -gt $keep_n  ; then
      rm $fileid
      if   $? != 0  ; then
         echo "$0 error $? erasing the old ($i_th)th log named $fileid."
         echo "  (continuing...)"
         fi
      fi
   done

exit $exit_status

ATOM RSS1 RSS2