Listing 1: Boot-up check disk script

#
# Copyright 1994, Lehman Brothers, Inc.
#
# Check all 4.2 devices and swap devices in /etc/fstab, and all Sybase devices.
# Notes: tell is a local utility that sends alphanumeric pages
#        sysdoc is the alias for the SAs for the domain
#
# Lehman Fixed Income Research naming conventions for Sybase partition search:
#   There is a start script ~sybase/install/RUN_<Servername> for each
#   dataserver on the host.
#
#   There is a device list ${DbaHome}/files/<Servername>.device_list for
#   each dataserver on the host.
#
#   You will need to modify the script if your conventions differ.

#
# notify - function to tell only at civilized times
#
notify()
{
  if [ -f /usr/local/bin/tell ]; then
     Now=`date +%H`
     if [ $Now -lt 23 -a $Now -ge 6 ];then
       /usr/local/bin/tell ${sysDoc} ${msg} >/dev/null 2>&1 &
     else
       at 6:00 <<!EOF!
/usr/local/bin/tell "${sysDoc}" "${msg}" >/dev/null 2>&1
!EOF!
     fi
  fi

  echo $msg | /usr/ucb/mail -s "`hostname` rebooted" ${sysDoc}
}

#
# notify_stat - function to tell immediately
#
notify_stat()
{
  if [ -f /usr/local/bin/tell ]; then
     /usr/local/bin/tell ${sysDoc} ${msg} >/dev/null 2>&1 &
  fi

  echo $msg | /usr/ucb/mail -s "`hostname` rebooted" ${sysDoc}
}

diskStat=""
sysDoc=`ypmatch sysdoc aliases | sed -e "s/, /,/"``
#
#Locate all file system and swap partitions
#
fsPart=`grep -v "^#" /etc/fstab | awk `$3=="4.2" || $2=="swap" {print $1}' `
#
# Locate all sybase servers, and follow local conventions to identify
# their partitions
#
if [ -d /usr/local/sybase/install ]; then
  sybServers=`cd /usr/local/sybase/install; ls RUN_* 2>/dev/null|fgrep -v
               startup|sed -e "s/RUN_//"`

  for serv in ${sybServers} ; do
	if [ -f /export/home/dba/files/${serv}.device_list ]; then
	   sybPart="$sybPart `cat /export/home/dba/files/${serv}.device_list`"
	fi
  done
else
  sybPart=""
fi
#
# Check all partitions
#
for devPart in ${fsPart} ${sybPart}; do
   /bin/dd if=${devPart} of=/dev/null count=1 2> /dev/null
   if [ $? -ne 0 ] ; then
     /usr/ucb/logger -t chkdisk -p user.err "Error reading ${devPart}"
     diskStat="${diskStat}${devPart} "
   fi
done

bootTime=`date +%T`
if [ -z "$diskStat" ]; then
#
# No error, do civilized notification
#
   /usr/ucb/logger -t chkdisk -p user.err "Disk check passed."
   msg="`hostname` rebooted at ${bootTime}, all disks ok."
   notify
else
#
# Disk not spinning, notify at any hour
#
   /usr/ucb/logger -t chkdisk -p user.err "Disk check failed: ${diskStat}."
   msg="`hostname` rebooted at ${bootTime}, disk failures: $diskStat."
   notify_stat
fi

exit 0

