/[dtapublic]/projs/trunk/projs/20161029_server_scripts_automaint_cron/master_logged
ViewVC logotype

Diff of /projs/trunk/projs/20161029_server_scripts_automaint_cron/master_logged

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 59 by dashley, Sat Oct 29 20:47:33 2016 UTC revision 60 by dashley, Sat Oct 29 21:06:08 2016 UTC
# Line 1  Line 1 
1  #!/bin/bash  #!/bin/bash
2  #-------------------------------------------------------------------------------------------------  #-------------------------------------------------------------------------------------------------
3  #$Header$  #$Header$
4  #-------------------------------------------------------------------------------------------------  #-------------------------------------------------------------------------------------------------
5  #This file is part of "Server Scripts, Automatic Maintenance, Cron", a set of scripts for  #This file is part of "Server Scripts, Automatic Maintenance, Cron", a set of scripts for
6  #performing automatic periodic maintenance on a Linux server.  #performing automatic periodic maintenance on a Linux server.
7  #-------------------------------------------------------------------------------------------------  #-------------------------------------------------------------------------------------------------
8  #This source code and any program in which it is compiled/used is provided under the MIT License,  #This source code and any program in which it is compiled/used is provided under the MIT License,
9  #reproduced below.  #reproduced below.
10  #-------------------------------------------------------------------------------------------------  #-------------------------------------------------------------------------------------------------
11  #Permission is hereby granted, free of charge, to any person obtaining a copy of  #Permission is hereby granted, free of charge, to any person obtaining a copy of
12  #this software and associated documentation files(the "Software"), to deal in the  #this software and associated documentation files(the "Software"), to deal in the
13  #Software without restriction, including without limitation the rights to use,  #Software without restriction, including without limitation the rights to use,
14  #copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the  #copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the
15  #Software, and to permit persons to whom the Software is furnished to do so,  #Software, and to permit persons to whom the Software is furnished to do so,
16  #subject to the following conditions :  #subject to the following conditions :
17  #  #
18  #The above copyright notice and this permission notice shall be included in all  #The above copyright notice and this permission notice shall be included in all
19  #copies or substantial portions of the Software.  #copies or substantial portions of the Software.
20  #  #
21  #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  #THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22  #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  #IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23  #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE  #FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
24  #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  #AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25  #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,  #LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26  #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE  #OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27  #SOFTWARE.  #SOFTWARE.
28  #-------------------------------------------------------------------------------------------------  #-------------------------------------------------------------------------------------------------
29  #This is the cron script, invoked hourly, to perform automatic  #This is the cron script, invoked hourly, to perform automatic
30  #maintenance.  All stdout and stderr output is logged.  #maintenance.  All stdout and stderr output is logged.
31  #  #
32  #The parameters that this script expects are:  #The parameters that this script expects are:
33  #  #
34  #    1)Year (4-digit)  #    1)Year (4-digit)
35  #    2)Year (2-digit)  #    2)Year (2-digit)
36  #    3)Month (long text)  #    3)Month (long text)
37  #    4)Month (short text)  #    4)Month (short text)
38  #    5)Month (2-digit)  #    5)Month (2-digit)
39  #    6)Day of month (2-digit)  #    6)Day of month (2-digit)
40  #    7)Day of week (long text)  #    7)Day of week (long text)
41  #    8)Day of week (short text)  #    8)Day of week (short text)
42  #    9)Day of week (single digit)  #    9)Day of week (single digit)
43  #   10)Hour (24-hour, 2-digit)  #   10)Hour (24-hour, 2-digit)
44  #   11)Hour (12-hour, 2-digit)  #   11)Hour (12-hour, 2-digit)
45  #   12)AM or PM, as a text string  #   12)AM or PM, as a text string
46  #   13)Minutes (2-digit)  #   13)Minutes (2-digit)
47  #   14)Seconds (2-digit)  #   14)Seconds (2-digit)
48  #  #
49  #Change to a safe working directory in case something goes wrong,  #Change to a safe working directory in case something goes wrong,
50  #especially a failed cd followed by a mass delete.  #especially a failed cd followed by a mass delete.
51  cd /root/cronjob_sandbox  cd /root/cronjob_sandbox
52  #  #
53  /etc/cron.custom/scripts/hline_thin  /etc/cron.custom/scripts/hline_thin
54  echo "Automatic maintenance nominally beginning on $7, $1/$5/$6 at ${10}:${13}:${14}."  echo "Automatic maintenance nominally beginning on $7, $1/$5/$6 at ${10}:${13}:${14}."
55  /etc/cron.custom/scripts/hline_thin  /etc/cron.custom/scripts/hline_thin
56  ACTUAL_TIMESTAMP=`date`  ACTUAL_TIMESTAMP=`date`
57  echo -n "Automatic maintenance actually beginning at "  echo -n "Automatic maintenance actually beginning at "
58  echo -n ${ACTUAL_TIMESTAMP}  echo -n ${ACTUAL_TIMESTAMP}
59  echo "."  echo "."
60  /etc/cron.custom/scripts/hline_thin  /etc/cron.custom/scripts/hline_thin
61  echo "This maintenance is scheduled hourly; and may include hourly, daily,"  echo "This maintenance is scheduled hourly; and may include hourly, daily,"
62  echo "weekly, and monthly maintenance activity (depending on the hour of the"  echo "weekly, and monthly maintenance activity (depending on the hour of the"
63  echo "day, the day of the week, and the day of the month)."  echo "day, the day of the week, and the day of the month)."
64  /etc/cron.custom/scripts/hline_thin  /etc/cron.custom/scripts/hline_thin
65  #-----------------------------------------------------------------------------  #-----------------------------------------------------------------------------
66  #Establish Booleans to decide which types of maintenance will not and  #Establish Booleans to decide which types of maintenance will not and
67  #will be performed this run.  #will be performed this run.
68  #  #
69  BOOLEAN_HOURLY=1  BOOLEAN_HOURLY=1
70  echo    "HOURLY  maintenance WILL     be performed."  echo    "HOURLY  maintenance WILL     be performed."
71    
72  if [ ${10} = "01" ] ; then  if [ ${10} = "01" ] ; then
73     BOOLEAN_DAILY=1     BOOLEAN_DAILY=1
74     echo "DAILY   maintenance WILL     be performed."     echo "DAILY   maintenance WILL     be performed."
75  else  else
76     BOOLEAN_DAILY=0     BOOLEAN_DAILY=0
77     echo "DAILY   maintenance WILL NOT be performed."     echo "DAILY   maintenance WILL NOT be performed."
78  fi  fi
79    
80  #  #
81  #BOOLEAN_DAILY=1  #BOOLEAN_DAILY=1
82  #Above line for debug only.  #Above line for debug only.
83  #  #
84  #Note below:  6 is Saturday, 0 is Sunday.  #Note below:  6 is Saturday, 0 is Sunday.
85  #  #
86  if [ $BOOLEAN_DAILY = "1" ] && [ ${9} = "6" ] ; then  if [ $BOOLEAN_DAILY = "1" ] && [ ${9} = "6" ] ; then
87     BOOLEAN_WEEKLY=1     BOOLEAN_WEEKLY=1
88     echo "WEEKLY  maintenance WILL     be performed."     echo "WEEKLY  maintenance WILL     be performed."
89  else  else
90     BOOLEAN_WEEKLY=0     BOOLEAN_WEEKLY=0
91     echo "WEEKLY  maintenance WILL NOT be performed."     echo "WEEKLY  maintenance WILL NOT be performed."
92  fi  fi
93    
94  if [ $BOOLEAN_DAILY = "1" ] && [ ${6} = "01" ] ; then  if [ $BOOLEAN_DAILY = "1" ] && [ ${6} = "01" ] ; then
95     BOOLEAN_MONTHLY=1     BOOLEAN_MONTHLY=1
96     echo "MONTHLY maintenance WILL     be performed."     echo "MONTHLY maintenance WILL     be performed."
97  else  else
98     BOOLEAN_MONTHLY=0     BOOLEAN_MONTHLY=0
99     echo "MONTHLY maintenance WILL NOT be performed."     echo "MONTHLY maintenance WILL NOT be performed."
100  fi  fi
101    
102  #Debug  #Debug
103  #BOOLEAN_WEEKLY=1  #BOOLEAN_WEEKLY=1
104    
105  /etc/cron.custom/scripts/hline_thin  /etc/cron.custom/scripts/hline_thin
106  #-----------------------------------------------------------------------------  #-----------------------------------------------------------------------------
107  #Loop through and do the hourly maintenance.  This involves finding  #Loop through and do the hourly maintenance.  This involves finding
108  #all the scripts ending in "hourly" and executing them in alphabetical  #all the scripts ending in "hourly" and executing them in alphabetical
109  #order.  #order.
110  #  #
111  #Note on below:  should investigate more reliable alternative using SED.  #Note on below:  should investigate more reliable alternative using SED.
112  if [ $BOOLEAN_HOURLY = "1" ] ; then  if [ $BOOLEAN_HOURLY = "1" ] ; then
113     HOURLY_FILES=`ls -1 /etc/cron.custom/cronjobs/*|sort|grep .hourly`     HOURLY_FILES=`ls -1 /etc/cron.custom/cronjobs/*|sort|grep .hourly`
114     for fname in $HOURLY_FILES     for fname in $HOURLY_FILES
115     do     do
116       #Change to a safe working directory in case something goes wrong,       #Change to a safe working directory in case something goes wrong,
117       #especially a failed cd followed by a mass delete.       #especially a failed cd followed by a mass delete.
118       cd /root/cronjob_sandbox       cd /root/cronjob_sandbox
119       #       #
120       echo "Executing" $fname "as part of hourly maintenance."       echo "Executing" $fname "as part of hourly maintenance."
121       /etc/cron.custom/scripts/hline_thin       /etc/cron.custom/scripts/hline_thin
122       ${fname} ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14}       ${fname} ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14}
123       /etc/cron.custom/scripts/hline_thin       /etc/cron.custom/scripts/hline_thin
124       #       #
125       #Change to a safe working directory in case something goes wrong,       #Change to a safe working directory in case something goes wrong,
126       #especially a failed cd followed by a mass delete.       #especially a failed cd followed by a mass delete.
127       cd /root/cronjob_sandbox       cd /root/cronjob_sandbox
128     done     done
129  fi  fi
130  #-----------------------------------------------------------------------------  #-----------------------------------------------------------------------------
131  #Prepare for the daily, weekly, and monthly maintenance.  This generally  #Prepare for the daily, weekly, and monthly maintenance.  This generally
132  #involves shutting daemons that might interfere with maintenance activities.  #involves shutting daemons that might interfere with maintenance activities.
133  #Find all the scripts ending in "premaint" and execute them in alphabetical  #Find all the scripts ending in "premaint" and execute them in alphabetical
134  #order.  #order.
135  #  #
136  #Note on below:  should investigate more reliable alternative using SED.  #Note on below:  should investigate more reliable alternative using SED.
137  if [ $BOOLEAN_DAILY = "1" ] || [ $BOOLEAN_WEEKLY = "1" ] || [ $BOOLEAN_MONTHLY = "1" ] ; then  if [ $BOOLEAN_DAILY = "1" ] || [ $BOOLEAN_WEEKLY = "1" ] || [ $BOOLEAN_MONTHLY = "1" ] ; then
138     PREMAINT_FILES=`ls -1 /etc/cron.custom/cronjobs/*|sort|grep .premaint`     PREMAINT_FILES=`ls -1 /etc/cron.custom/cronjobs/*|sort|grep .premaint`
139     for fname in $PREMAINT_FILES     for fname in $PREMAINT_FILES
140     do     do
141       #Change to a safe working directory in case something goes wrong,       #Change to a safe working directory in case something goes wrong,
142       #especially a failed cd followed by a mass delete.       #especially a failed cd followed by a mass delete.
143       cd /root/cronjob_sandbox       cd /root/cronjob_sandbox
144       #       #
145       echo "Executing" $fname "to prepare for daily, weekly, and monthly maintenance."       echo "Executing" $fname "to prepare for daily, weekly, and monthly maintenance."
146       /etc/cron.custom/scripts/hline_thin       /etc/cron.custom/scripts/hline_thin
147       ${fname} ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14}       ${fname} ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14}
148       /etc/cron.custom/scripts/hline_thin       /etc/cron.custom/scripts/hline_thin
149       #       #
150       #Change to a safe working directory in case something goes wrong,       #Change to a safe working directory in case something goes wrong,
151       #especially a failed cd followed by a mass delete.       #especially a failed cd followed by a mass delete.
152       cd /root/cronjob_sandbox       cd /root/cronjob_sandbox
153     done     done
154  fi  fi
155  #-----------------------------------------------------------------------------  #-----------------------------------------------------------------------------
156  #Do the daily maintenance.  #Do the daily maintenance.
157  if [ $BOOLEAN_DAILY = "1" ] ; then  if [ $BOOLEAN_DAILY = "1" ] ; then
158     DAILY_FILES=`ls -1 /etc/cron.custom/cronjobs/*|sort|grep .daily`     DAILY_FILES=`ls -1 /etc/cron.custom/cronjobs/*|sort|grep .daily`
159     for fname in $DAILY_FILES     for fname in $DAILY_FILES
160     do     do
161       #Change to a safe working directory in case something goes wrong,       #Change to a safe working directory in case something goes wrong,
162       #especially a failed cd followed by a mass delete.       #especially a failed cd followed by a mass delete.
163       cd /root/cronjob_sandbox       cd /root/cronjob_sandbox
164       #       #
165       echo "Executing daily maintenance script" ${fname}.       echo "Executing daily maintenance script" ${fname}.
166       /etc/cron.custom/scripts/hline_thin       /etc/cron.custom/scripts/hline_thin
167       ${fname} ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14}       ${fname} ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14}
168       /etc/cron.custom/scripts/hline_thin       /etc/cron.custom/scripts/hline_thin
169       #       #
170       #Change to a safe working directory in case something goes wrong,       #Change to a safe working directory in case something goes wrong,
171       #especially a failed cd followed by a mass delete.       #especially a failed cd followed by a mass delete.
172       cd /root/cronjob_sandbox       cd /root/cronjob_sandbox
173     done     done
174  fi  fi
175  #-----------------------------------------------------------------------------  #-----------------------------------------------------------------------------
176  #Do the weekly maintenance.  #Do the weekly maintenance.
177  if [ $BOOLEAN_WEEKLY = "1" ] ; then  if [ $BOOLEAN_WEEKLY = "1" ] ; then
178     WEEKLY_FILES=`ls -1 /etc/cron.custom/cronjobs/*|sort|grep .weekly`     WEEKLY_FILES=`ls -1 /etc/cron.custom/cronjobs/*|sort|grep .weekly`
179     for fname in $WEEKLY_FILES     for fname in $WEEKLY_FILES
180     do     do
181       #Change to a safe working directory in case something goes wrong,       #Change to a safe working directory in case something goes wrong,
182       #especially a failed cd followed by a mass delete.       #especially a failed cd followed by a mass delete.
183       cd /root/cronjob_sandbox       cd /root/cronjob_sandbox
184       #       #
185       echo "Executing weekly maintenance script" ${fname}.       echo "Executing weekly maintenance script" ${fname}.
186       /etc/cron.custom/scripts/hline_thin       /etc/cron.custom/scripts/hline_thin
187       ${fname} ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14}       ${fname} ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14}
188       /etc/cron.custom/scripts/hline_thin       /etc/cron.custom/scripts/hline_thin
189       #       #
190       #Change to a safe working directory in case something goes wrong,       #Change to a safe working directory in case something goes wrong,
191       #especially a failed cd followed by a mass delete.       #especially a failed cd followed by a mass delete.
192       cd /root/cronjob_sandbox       cd /root/cronjob_sandbox
193     done     done
194  fi  fi
195  #-----------------------------------------------------------------------------  #-----------------------------------------------------------------------------
196  #Do the monthly maintenance.  #Do the monthly maintenance.
197  if [ $BOOLEAN_MONTHLY = "1" ] ; then  if [ $BOOLEAN_MONTHLY = "1" ] ; then
198     MONTHLY_FILES=`ls -1 /etc/cron.custom/cronjobs/*|sort|grep .monthly`     MONTHLY_FILES=`ls -1 /etc/cron.custom/cronjobs/*|sort|grep .monthly`
199     for fname in $MONTHLY_FILES     for fname in $MONTHLY_FILES
200     do     do
201       #Change to a safe working directory in case something goes wrong,       #Change to a safe working directory in case something goes wrong,
202       #especially a failed cd followed by a mass delete.       #especially a failed cd followed by a mass delete.
203       cd /root/cronjob_sandbox       cd /root/cronjob_sandbox
204       #       #
205       echo "Executing monthly maintenance script" ${fname}.       echo "Executing monthly maintenance script" ${fname}.
206       /etc/cron.custom/scripts/hline_thin       /etc/cron.custom/scripts/hline_thin
207       ${fname} ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14}       ${fname} ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14}
208       /etc/cron.custom/scripts/hline_thin       /etc/cron.custom/scripts/hline_thin
209       #       #
210       #Change to a safe working directory in case something goes wrong,       #Change to a safe working directory in case something goes wrong,
211       #especially a failed cd followed by a mass delete.       #especially a failed cd followed by a mass delete.
212       cd /root/cronjob_sandbox       cd /root/cronjob_sandbox
213     done     done
214  fi  fi
215  #-----------------------------------------------------------------------------  #-----------------------------------------------------------------------------
216  #Recover from the daily, weekly, and monthly maintenance.  This generally  #Recover from the daily, weekly, and monthly maintenance.  This generally
217  #involves restarting daemons.  Find all the scripts ending in "postmaint"  #involves restarting daemons.  Find all the scripts ending in "postmaint"
218  #and execute them in alphabetical order.  #and execute them in alphabetical order.
219  #  #
220  #Note on below:  should investigate more reliable alternative using SED.  #Note on below:  should investigate more reliable alternative using SED.
221  if [ $BOOLEAN_DAILY = "1" ] || [ $BOOLEAN_WEEKLY = "1" ] || [ $BOOLEAN_MONTHLY = "1" ] ; then  if [ $BOOLEAN_DAILY = "1" ] || [ $BOOLEAN_WEEKLY = "1" ] || [ $BOOLEAN_MONTHLY = "1" ] ; then
222     POSTMAINT_FILES=`ls -1 /etc/cron.custom/cronjobs/*|sort|grep .postmaint`     POSTMAINT_FILES=`ls -1 /etc/cron.custom/cronjobs/*|sort|grep .postmaint`
223     for fname in $POSTMAINT_FILES     for fname in $POSTMAINT_FILES
224     do     do
225       #Change to a safe working directory in case something goes wrong,       #Change to a safe working directory in case something goes wrong,
226       #especially a failed cd followed by a mass delete.       #especially a failed cd followed by a mass delete.
227       cd /root/cronjob_sandbox       cd /root/cronjob_sandbox
228       #       #
229       echo "Executing" $fname "to recover from daily, weekly, and monthly maintenance."       echo "Executing" $fname "to recover from daily, weekly, and monthly maintenance."
230       /etc/cron.custom/scripts/hline_thin       /etc/cron.custom/scripts/hline_thin
231       ${fname} ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14}       ${fname} ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12} ${13} ${14}
232       /etc/cron.custom/scripts/hline_thin       /etc/cron.custom/scripts/hline_thin
233       #       #
234       #Change to a safe working directory in case something goes wrong,       #Change to a safe working directory in case something goes wrong,
235       #especially a failed cd followed by a mass delete.       #especially a failed cd followed by a mass delete.
236       cd /root/cronjob_sandbox       cd /root/cronjob_sandbox
237     done     done
238  fi  fi
239  #-----------------------------------------------------------------------------  #-----------------------------------------------------------------------------
240  #Change to a safe working directory in case something goes wrong,  #Change to a safe working directory in case something goes wrong,
241  #especially a failed cd followed by a mass delete.  #especially a failed cd followed by a mass delete.
242  cd /root/cronjob_sandbox  cd /root/cronjob_sandbox
243  #  #
244  ACTUAL_TIMESTAMP=`date`  ACTUAL_TIMESTAMP=`date`
245  echo -n "Automatic maintenance actually ending at "  echo -n "Automatic maintenance actually ending at "
246  echo -n ${ACTUAL_TIMESTAMP}  echo -n ${ACTUAL_TIMESTAMP}
247  echo "."  echo "."
248  /etc/cron.custom/scripts/hline_thin  /etc/cron.custom/scripts/hline_thin
249  #hline_thick no longer necessary because not concatening logs together, as  #hline_thick no longer necessary because not concatening logs together, as
250  #these scripts were changed to be more SSD-friendly.  #these scripts were changed to be more SSD-friendly.
251  #/etc/cron.custom/scripts/hline_thick  #/etc/cron.custom/scripts/hline_thick
252  #  #
253  #End of script.  #End of script.

Legend:
Removed from v.59  
changed lines
  Added in v.60

dashley@gmail.com
ViewVC Help
Powered by ViewVC 1.1.25