Initial add of defaria.com
[clearscm.git] / defaria.com / Computers / code / adm / bin / daily
1 #!/bin/bash
2 ################################################################################
3 #
4 # File:         daily
5 # Description:  This is the daily cronjob for root
6 # Author:       Andrew@DeFaria.com
7 # Created:      Wed Jul 21 12:12:28 PDT 1999
8 # Modified:
9 # Language:     Korn Shell
10 #
11 # (c) Copyright 2001, Andrew@DeFaria.com, all rights reserved
12 #
13 ################################################################################
14 me=$(basename $0)
15
16 # Set adm_base
17 adm_base=${adm_base:-//sonscentral/Corporate/Software/adm}
18
19 # Set adm_fpath
20 adm_fpath=${adm_fpath:-$adm_base/functions}
21
22 # Source functions
23 . $adm_fpath/common
24
25 # Add $adm_base/bin and $adm_base/clearcase PATH
26 export PATH=$adm_base/bin:$adm_base/clearcase:$PATH
27
28 # Source in tmpfiles function
29 tmpprefix=${TMPDIR:-/tmp}/$me.$$
30 tmpfile=$tmpprefix
31 . $adm_fpath/tmpfiles
32 arm_trap
33
34 # Where logs are kept
35 logs=$adm_host/logs
36
37 # Define admin_host. Admin_host is the machine where checks for the network
38 # as a whole are run (such as check_view_storage)
39 admin_host=dreamcicle # For now...
40
41 verbose=
42 debug=
43
44 function usage {
45   display "$me [-v|verbose] [-d|debug] [-u|usage] [-n|notify <email address>]"
46   display "        -v|verbose:     Turns on verbose mode"
47   display "        -d|debug:       Turns on debug mode"
48   display "        -u|usage:       Print this usage message\n"
49   display "        -n|notify:      Who to notify of problems (default root)"
50
51   error "$1" 1
52 } # usage
53
54 lab_admin=cdsadmin # For now
55 local_admin=cdsadmin
56
57 function notify {
58   debug "ENTER notify"
59   who=$1
60   logfile=$2
61
62   cat > $tmpfile <<END
63 Notice: $me cronjob discovered the following problems:
64
65 END
66
67   cat $logfile >> $tmpfile
68
69   mailx -s "Notice: $me cronjob discovered the following problems" $who <
70 $tmpfile
71   debug "EXIT notify"
72 } # notify
73
74 # Get parameters
75 while [ $# -ge 1 ]; do
76   case "$1" in
77     -usage)
78       usage
79     ;;
80
81     -v|-verbose)
82       verbose=yes
83     ;;
84
85     -d|-debug)
86       debug=yes
87     ;;
88
89     -n|-notify)
90       shift
91       if [ $# -lt 1 ]; then
92         error "Notify email address was unspecified!" 1
93       fi
94       local_admin="$1"
95     ;;
96
97     *)
98       usage "Unrecognized parameter $1"
99     ;;
100   esac
101   shift
102 done
103
104 ## Main
105 # Some common portions of log filenames:
106 host=$(uname -n) # System's name
107 date=$(date +%d) # Note we keep one month of rolling logs
108
109 if [ "$host" = "$admin_host" ]; then
110   network_diskspace_log=$logs/network.diskspace.$date.log
111   verbose "Diskspace Report -> $network_diskspace_log"
112   diskspace -network > $network_diskspace_log 2>&1
113
114   if [ -s $network_diskspace_log ]; then
115     notify $lab_admin $network_diskspace_log
116   fi
117
118   view_storage_log=$logs/viewstorage.$date.log
119   verbose "View Storage Report -> $view_storage_log"
120   check_view_storage > $view_storage_log 2>&1
121
122   if [ -s $view_storage_log ]; then
123     notify $lab_admin $view_storage_log
124   fi
125
126   # Produce a viewspace report for all production view servers
127   viewservers="cds-sundev-rem canon"
128
129   for viewserver in $viewservers; do
130     viewspace_log=$logs/$viewserver.viewspace.$date.log
131     verbose "Viewspace Report for $viewserver -> $viewspace_log"
132     viewspace -host $viewserver > $viewspace_log
133   done
134 fi
135
136 # Checks run on all machines
137 local_diskspace_log=$logs/$host.diskspace.$date.log
138 verbose "Diskspace Report -> $local_diskspace_log"
139 diskspace -local > $local_diskspace_log 2>&1
140
141 if [ -s $local_diskspace_log ]; then
142   notify local_admin $local_diskspace_log
143 fi
144
145 machine_configuration_log=$logs/$host.machine_configuration.$date.log
146 verbose "Machine Configuration Report -> $machine_configuration_log" 2>&1 &
147 configure_machine -f > $machine_configuraton_log 2>&1
148
149 if [ -s $machine_configuration_log ]; then
150   notify local_admin $machine_configuration_log
151 fi