"Fossies" - the Fresh Open Source Software Archive

Member "atop-2.8.1/45atoppm" (7 Jan 2023, 1186 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.

    1 #!/bin/sh
    2 
    3 . "${PM_FUNCTIONS}"
    4 
    5 LOGPATH=/var/log/atop
    6 BINPATH=/usr/bin
    7 PIDFILE=/var/run/atop.pid
    8 INTERVAL=600        # interval 10 minutes
    9 CURDAY=`date +%Y%m%d`   # current date in same format
   10 
   11 # If the system suspends, one final sample will be taken for the logfile
   12 #
   13 suspend_atop()
   14 {
   15     if [ -e $PIDFILE ] && ps -p `cat $PIDFILE` | grep 'atop$' > /dev/null
   16     then
   17         kill -USR2 `cat $PIDFILE`   # final sample and terminate
   18 
   19         CNT=0
   20 
   21         while ps -p `cat $PIDFILE` > /dev/null
   22         do
   23             let CNT+=1
   24 
   25             if [ $CNT -gt 5 ]
   26             then
   27                 break;
   28             fi
   29 
   30             sleep 1
   31         done
   32     fi
   33 }
   34 
   35 # If the system resumes, a new atop will be started (similar to boot)
   36 #
   37 resume_atop()
   38 {
   39     # in case atop is running, stop it
   40     #
   41     if [ -e $PIDFILE ] && ps -p `cat $PIDFILE` | grep 'atop$' > /dev/null
   42     then
   43         kill -TERM `cat $PIDFILE`
   44         rm $PIDFILE
   45         sleep 1
   46     fi
   47 
   48     # start atop
   49     #
   50     $BINPATH/atop -R -w $LOGPATH/atop_$CURDAY $INTERVAL \
   51                      > $LOGPATH/daily.log 2>&1 &
   52     echo $! > $PIDFILE
   53     
   54     # delete logfiles older than four weeks
   55     #
   56     (
   57         sleep 3;
   58         find $LOGPATH -name 'atop_*' -mtime +28 -exec rm {} \;
   59     )&
   60 
   61     exit 0
   62 }
   63 
   64 case "$1" in
   65     hibernate|suspend)
   66         suspend_atop
   67         ;;
   68     thaw|resume)
   69         resume_atop
   70         ;;
   71     *)  exit $NA
   72         ;;
   73 esac