打印

/opt/hpservices/RemoteSupport/config/pruneIncidents.sh

/opt/hpservices/RemoteSupport/config/pruneIncidents.sh

1  #!/bin/sh
     2  #set -xv
     3  #############i################################
     4  # FILE:  pruneIncidents.sh
     5  # DESCRIPTION:  This file removes logfiles of
     6  #   resolved, withdrawn, and expired incidents
     7  #   from the client file system.  It is called
     8  #   by a cron job to keep the file system from
     9  #   filling up without bound.
    10  #
    11  #   Works by removing all the incident.dat files
    12  #   from /var/opt/hpservices/incidents/<incidentID>
    13  #   that are older than the MAXCLOSEDINCIDENTAGE
    14  #   specified in
    15  #   /opt/hpservices/RemoteSupport/config/ISEEConstants.properties
    16  #   and have the "State" variable set to
    17  #   7, 8 , or 9.
    18  # @(#) $ Header: $
    19  # (c) Hewlett-Packard 2000-2003, All Rights Reserved
    20  ###############################################
    21  PATH="/usr/bin:/usr/sbin:/bin:/usr/xpg4/bin/"
    22  INCIDENTDIR="/var/opt/hpservices/incidents"
    23  PRUNELOG="/opt/hpservices/log/pruneIncidents.log"
    24  DATE=`date`
    25  MACHINE=`uname`
    26
    27  # Source in properties file to get MAXCLOSEDINCIDENTAGE
    28  . /opt/hpservices/RemoteSupport/config/ISEEConstants.properties
    29  if [ $? -ne 0 ]; then #Property file missing - do not know age to prune files.
    30    exit 1
    31  fi
    32
    33  . /opt/hpservices/RemoteSupport/config/commonFunctions
    34  trimLogFile $PRUNELOG
    35
    36    cd $INCIDENTDIR
    37    # find local incidents
    38
    39    if [ "$MACHINE" != "SunOS" ];then
    40    incidentDirs=`/usr/bin/find .`
    41    else
    42    incidentDirs=`/usr/xpg4/bin/ls .`
    43    fi
    44
    45   if [ $? -eq 0 ]; then # incident subdirectories readable
    47     # stop daemon
    48     if [ ! -f $PRUNELOG ]; then
    49       touch $PRUNELOG
    50     fi
    51
    52    ps -ef | grep -i RunMap | grep -v grep >> Mapcheck$$
    53    MAPVALUE=`cat Mapcheck$$ | grep -i Map`
    54    rm -rf Mapcheck$$
    55
    56  echo "$DATE :  Verifying whether RunMap is running or not" >> $PRUNELOG
    57
    58     # Check for RunMap which is getting executed while pruneIncident is running
    59     i=0
    60     while [ $i -le 0 ]; do
    61     if [ "$MAPVALUE" ]; then
    62       echo "$DATE :  RunMap is running " >> $PRUNELOG
    63       sleep 10
    64       ps -ef | grep -i RunMap  | grep -v grep >> Mapcheck2$$
    65       MAPVALUE=`cat Mapcheck2$$ | grep -i Map`
    66       rm -rf Mapcheck2$$
    67       DATE=`date`
    68       i=0
    69     else
    70       echo "$DATE :  RunMap is not running " >> $PRUNELOG
    71       i=1
    72     fi
    73    done
    74
    75     echo "$DATE :  Stopping mad" >> $PRUNELOG
    76     /opt/hpservices/etc/hpservices stop > /dev/null 2>&1
    77     if [ $? -eq 0 ];then
    78     echo "$DATE :  Mad has been Stopped " >> $PRUNELOG
    79     else
    80     echo "$DATE :  Failed to stop Mad  ! " >> $PRUNELOG
    81     exit 1
    82     fi
    83
    84
    85
    86
    87  # Block for UNIX Operating Systems other than Solaris
    88
    89  if [ "$MACHINE" != "SunOS" ];then
    90
    91         # find all incident.dat files under $INCIDENTDIR that have "State" set to 7, 8, or 9.
    92         closedIncidents=""
    93         closedIncidents=`echo $incidentDirs | grep incident.dat |  /usr/bin/xargs grep -e "State = 7" -e "State =
8" -e "State = 9" | /usr/bin/cut -d: -f1`
    94         echo "$DATE :  List of all Closed Incidents" >> $PRUNELOG
    95         echo ""
    96         echo $closedIncidents >> $PRUNELOG
    97         echo ""
    98
    99           # find ClosedIncidents that are newer than max closed incident age
   100           #  i=0
   101             newClosedIncidentDirs=""
   102
   103             newClosedIncidentDirs=`/usr/bin/find . -mtime -$MAXCLOSEDINCIDENTAGE -print | /usr/bin/xargs grep -e
"State = 7" -e "State = 8" -e "State = 9" | /usr/bin/cut -d: -f1`
   104
   105                    echo "$DATE :  List of all Closed Incidents which are less than $MAXCLOSEDINCIDENTAGE  days ol
d"   >> $PRUNELOG
   106
   107                    echo ""
   108                    echo $newClosedIncidentDirs  >> $PRUNELOG
   109                    echo ""
   110
   111                      for i in $closedIncidents; do
   112                          closedIncidentDir=`/usr/bin/dirname $i`
   113
   114                               echo $newClosedIncidentDirs | grep -q $i
   115
   116                               if [ $? -ne 0 ]; then # closed incident is not new - remove it.
   117                                  echo "$DATE :  Removing the directory $closedIncidentDir" >> $PRUNELOG
   118
   119                                  rm -rf $closedIncidentDir
   120                                  if [ $? -eq 0 ];then
   121                                  echo "$DATE :  Removed Successfully directory $closedIncidentDir" >> $PRUNELOG
   122                                  else
   123                                  echo "$DATE :  Failed in Removing the directory $closedIncidentDir" >> $PRUNELOG
   124                                  fi
   125
   126                                   #else
   127                                   #  echo "$i is closed, but it is too new to remove."
   128                                fi
   129                    done
   130
   131  else
   132
   133     # Block for only Solaris Operating System
   134     # find all incident.dat files under $INCIDENTDIR that have "State" set to 7, 8, or 9.
   135     closedDir=""
   136     for i in $incidentDirs; do
   137         closedDir=`/usr/bin/find $i -mtime +$MAXCLOSEDINCIDENTAGE -print | /usr/bin/xargs /usr/xpg4/bin/grep -e "
State = 7" -e "State = 8" -e "State = 9" | /usr/bin/cut -d: -f1`
   138
   139          if [ $closedDir ]; then
   140            echo "$DATE: $i is marked for deletion." >> $PRUNELOG
   141            rm -rf $i > /dev/null
   142            if [ $? -eq 0 ] ; then
   143              echo "$DATE: Successfully removed $i" >> $PRUNELOG
   144            fi
   145          else
   146            echo "$DATE: $i is not marked for deletion." >> $PRUNELOG
   147          fi
   148     done
   149
   150  fi
   151
   152   # start daemon
   153    echo "$DATE :  Starting Mad Daemon " >> $PRUNELOG
   154    /opt/hpservices/etc/hpservices start > /dev/null 2>&1
   155    if [ $? -eq 0 ];then
   156       echo "$DATE :  Mad Started Successfully" >> $PRUNELOG
   157       echo "-----------------------------------------" >> $PRUNELOG
   158       echo "+++++++++++++++++++++++++++++++++++++++++" >> $PRUNELOG
   159    else
   160       echo "$DATE :  Failed to start Mad  ! " >> $PRUNELOG
   161       echo "-----------------------------------------" >> $PRUNELOG
   162       echo "+++++++++++++++++++++++++++++++++++++++++" >> $PRUNELOG
   163    fi
   164
   165   fi # end of block incident subdirectories readable and also pruneIncidents.sh script

TOP

/opt/hpservices/contrib/SysInfo/bin/SysInfoRunMap.sh

1  #!/bin/sh
     2  # Copyright 2002 Hewlett-Packard Company.
     3  # All rights reserved.
     4  #
     5  # Title:         Utility script to launch ISEE Run Map interface
     6  # Author:        Zahid Khan
     7  # Organization:  HPCS R&D Mobile/E-Service
     8  # RCS:           $Header: /partners/SysInfo/Client/HPUXBuild/bin/SysInfoRunMap.sh 2 2005/04/15 04:55:12 -0600 sr
inivpu $
     9  #
    10  # NOTE: This is a no-charge contributed utility. Support for it
    11  #       will be provided on a best effort basis by Hewlett-Packard.
    12  #       Customers should direct any requests for updates, bug fixes,
    13  #       or enhancements to an HP support engineer.
    14  #       HP support engineers should direct such requests to their
    15  #       region LeadRCE.
    16  #
    17  # Version/Date/Comments(wrapped):
    18  # 1.00  04/2002    Created to allow SysInfo Mega Map to run from command line.
    19  # 1.01  03/2005    Add option to run both HPUX maps in succession, also
    20  #                  -tm <timeout-multiplier> option
    21  #
    22
    23  export PATH=/usr/bin
    24
    25  DEBUG=0
    26  TRACE=0
    27  BOTH_MAPS=0
    28  MIN_TM=2
    29  REAL_MIN_TM=10  # comprehensive .mmap's force 10 if not run from Insight!!
    30  MAX_TM=50
    31
    32  Prog=`basename $0`
    33  #===================================================================
    34  # fInitialize
    35  #        This function initializes values used by this utility.
    36  #===================================================================
    37  function fInitialize
    38  {
    39  # initialize to null configuration file variable
    40        if [ $TRACE -eq 1 ] ; then set -x ; fi
    41        RunMap="/opt/hpservices/RemoteSupport/bin/RunMap"
    42        mapName="ComprehensiveSystemInfo"
    43        mapName2="Addl_ComprehensiveInformation"
    44        area="Comprehensive System Information MAP run"
    45        area2="Additional Comprehensive System Information MAP run"
    46        desc="Command line invocation or cron collection"
    47        LOGFILE="/var/opt/hpservices/contrib/SysInfo/adm/SysInfoRunMap.log"
    48        RUNMAP_ARGS=""
    49
    50  # initialize other program values
    51          VERSION="1.01"
    52
    53  # return to main
    54
    55  }                       # end of fInitialize
    56
    57  #===================================================================
    58  # fPrintHeader          Print header message
    59  #===================================================================
    60  function fPrintHeader
    61  {
    62    if [ $TRACE -eq 1 ] ; then set -x ; fi
    63    print "# Started: $Prog (Version $VERSION) #" >> $LOGFILE
    64    print "# `date` map = $1 #" >> $LOGFILE
    65  }
    66
    67  #===================================================================
    68  # fPrintTrailer         Print trailer message
    69  #===================================================================
    70  function fPrintTrailer
    71  {
    72    if [ $TRACE -eq 1 ] ; then set -x ; fi
    73    print "# Stopped: $Prog #" >> $LOGFILE
    74    print "# `date` #" >> $LOGFILE
    75    print "##############################################" >> $LOGFILE
    76  }
    77
    78
    79  #===================================================================
    80  # fExit
    81  #               exiting installation utility
    82  #===================================================================
    83  function fExit
    84  {
    85     if [ $TRACE -eq 1 ] ; then set -x ; fi
    86     fPrintTrailer
    87     exit 0
    88  }
    89
    90  #===================================================================
    91  # setTimeoutMult
    92  #               evaluate and establish timeout multiplier
    93  #===================================================================
    94  function setTimeoutMult
    95  {
    96      if [ $TRACE -eq 1 ] ; then set -x ; fi
    97      tmval="$1"
    98      # first make sure it's an integer
    99      tmval_int=`expr match "$tmval" '^\([0-9][0-9]*\)$'` # try to parse it
   100      if [ -z "$tmval_int" -o "$tmval_int" != "$tmval" ] ; then
   101          echo "$Prog: ERROR: argument to -tm must be an integer" >&2
   102          exit 1
   103      fi
   104      # is it in valid range?
   105      if [ "$tmval" -lt "$MIN_TM" -o "$tmval" -gt "$MAX_TM" ] ; then
   106          echo "$Prog: ERROR: argument to -tm must be in the range" \
   107                  "$MIN_TM..$MAX_TM" >&2
   108          exit 1
   109      fi
   110
   111      ##################################################################
   112      # Hokey: if $tmval really is <= REAL_MIN_TM (10), do nothing
   113      # (See defn of REAL_TM_MIN above)
   114      if [ "$tmval" -le "$REAL_MIN_TM" ] ; then
   115          return
   116      fi
   117      ##################################################################
   118
   119      # all OK, set up RunMap argument
   120      RUNMAP_ARGS="$RUNMAP_ARGS -A timeMult=$tmval "
   121  }
   122
   123  #===================================================================
   124  # Usage
   125  #               Print Usage message
   126  #===================================================================
   127  function Usage
   128  {
   129  cat <<EOF
   130  Usage:
   131      $Prog [-both] [-tm <integer>]
   132  Options:
   133      -both          Run ComprehensiveSystemInfo MAP followed by the
   134                     Addl_ComprehensiveInformation MAP.  Default is to run
   135                     ComprehensiveSystemInfo only.
   136      -tm <integer>  Set Timeout-multipler.  <integer> must be in range $MIN_TM-$MAX_TM.
   137                     (Values less than 10 actually decrease the default multiplier
   138                     for Standard Configuration scheduled collections).
   139  EOF
   140  }
   141
   142  #===================================================================
   143  # Main Program
   144  #
   145  #===================================================================
   146  #===================================================================
   147
   148  fInitialize     # Initialize configuration variables
   149
   150  # Evaluate command-line
   151  while [ 1 ] ; do
   152          case "$1" in
   153                  "")     break;;
   154                  "-?"|-h) Usage; exit 0;;
   155                  -both)  BOTH_MAPS=1;;
   156                  -tm)    if [ -z "$2" ] ; then
   157                                  echo "$Prog: ERROR: -tm requires a numeric" \
   158                                          "argument" >&2
   159                                  exit 1
   160                          else
   161                                  setTimeoutMult "$2"
   162                                  shift
   163                          fi
   164                          ;;
   165                  -D)     DEBUG=1;;
   166                  -DD)    DEBUG=1 TRACE=1;;
   167                  *)      echo "$Prog: ERROR: unrecognized option: $1" >&2; exit 1;;
   168          esac
   169          shift
   170  done
   171
   172  if [ $TRACE -eq 1 ] ; then set -x ; fi
   173
   174  # look for RunMap Interface on the system
   175  if [[ -f $RunMap ]]
   176  then
   177    fPrintHeader $mapName
   178    echo "Invoking: $RunMap -n MapContent.$mapName -d -l" \
   179                  "-a \"$area\" -pd \"$desc\" $RUNMAP_ARGS" >> $LOGFILE
   180    $RunMap -n MapContent.$mapName -d -l -a "$area" -pd "$desc" $RUNMAP_ARGS \
   181          >> $LOGFILE 2>&1
   182
   183    retValue=$?
   184    if [ $retValue -ne 0 ]
   185    then
   186      print "WARNING" >> $LOGFILE
   187      print "ISEE RunMap interface returned, $retValue." >> $LOGFILE
   188      print " $mapName Map was not run." >> $LOGFILE
   189    else
   190      print "Map: $mapName, run successful." >> $LOGFILE
   191    fi
   192
   193    if [ $BOTH_MAPS -eq 1 ] ; then
   194      #
   195      # Run Addl_ComprehensiveInformation MAP, even if the Comprehensive one
   196      # just completed was unsuccessful
   197      #
   198      fPrintHeader $mapName2
   199      #if [ $DEBUG -eq 1 ] ; then
   200          echo "Invoking: $RunMap -n MapContent.$mapName2 -d -l" \
   201                  "-a \"$area2\" -pd \"$desc\" $RUNMAP_ARGS" >> $LOGFILE
   202      #fi
   203      $RunMap -n MapContent.$mapName2 -d -l -a "$area2" -pd "$desc" \
   204           $RUNMAP_ARGS >> $LOGFILE 2>&1
   205      retValue=$?
   206      if [ $retValue -ne 0 ]
   207      then
   208        print "WARNING" >> $LOGFILE
   209        print "ISEE RunMap interface returned, $retValue." >> $LOGFILE
   210        print " $mapName2 Map was not run." >> $LOGFILE
   211      else
   212        print "Map: $mapName2, run successful." >> $LOGFILE
   213      fi
   214    fi
   215  else
   216    print "WARNING" >> $LOGFILE
   217    print "ISEE RunMap interface not Found or is not accessible." >> $LOGFILE
   218    print "ComprehensiveSystemInfo Map was not run." >> $LOGFILE
   219  fi
   220
   221  fExit           # Exit the utility.
   222
   223
   224  # end of MAIN
   225

TOP

楼主是要。。。。。

TOP


感谢一直以来您对我们的支持!
当前时区 GMT+8, 现在时间是 2008-10-8 06:44 京ICP证060528 号

Designed By 17DST