/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