"Fossies" - the Fresh Open Source Software Archive

Member "atop-2.8.1/atop.daily" (7 Jan 2023, 1447 Bytes) of package /linux/misc/atop-2.8.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "atop.daily": 2.5.0_vs_2.6.0.

    1 #!/bin/sh
    2 
    3 LOGOPTS=""              # default options
    4 LOGINTERVAL=600             # default interval in seconds
    5 LOGGENERATIONS=28           # default number of days
    6 LOGPATH=/var/log/atop                   # default log location
    7 
    8 # allow administrator to overrule the variables
    9 # defined above
   10 #
   11 DEFAULTSFILE=/etc/default/atop      # possibility to overrule vars
   12 
   13 if [ -e "$DEFAULTSFILE" ]
   14 then
   15     . "$DEFAULTSFILE"
   16 
   17     # validate overruled variables
   18     # (LOGOPTS and LOGINTERVAL are implicitly by atop)
   19     #
   20     case "$LOGGENERATIONS" in
   21         ''|*[!0-9]*)
   22         echo non-numerical value for LOGGENERATIONS >&2
   23         exit 1;;
   24     esac
   25 fi
   26 
   27 CURDAY=`date +%Y%m%d`
   28 BINPATH=/usr/bin
   29 PIDFILE=/var/run/atop.pid
   30 
   31 # verify if atop still runs for daily logging
   32 #
   33 if [ -e "$PIDFILE" ] && ps -p `cat "$PIDFILE"` | grep 'atop$' > /dev/null
   34 then
   35     kill -USR2 `cat "$PIDFILE"`       # final sample and terminate
   36 
   37     CNT=0
   38 
   39     while ps -p `cat "$PIDFILE"` > /dev/null
   40     do
   41         CNT=$((CNT + 1))
   42 
   43         if [ $CNT -gt 5 ]
   44         then
   45             break;
   46         fi
   47 
   48         sleep 1
   49     done
   50 
   51     rm "$PIDFILE"
   52 fi
   53 
   54 # delete logfiles older than N days (configurable)
   55 # start a child shell that activates another child shell in
   56 # the background to avoid a zombie
   57 #
   58 ( (sleep 3; find "$LOGPATH" -name 'atop_*' -mtime +"$LOGGENERATIONS" -exec rm {} \;)& )
   59 
   60 # activate atop with an interval of S seconds (configurable),
   61 # replacing the current shell
   62 #
   63 echo $$ > $PIDFILE
   64 exec $BINPATH/atop $LOGOPTS -w "$LOGPATH"/atop_"$CURDAY" "$LOGINTERVAL" > "$LOGPATH/daily.log" 2>&1