#!/bin/sh
#set -x
# script updates boot archive list
# this has to be done every time there is change on system, like install new patch
# but this is usually forgoten, so I run this through cronjob
# =====================================================================
# Only the root user can update boot archive
if [ "`/usr/bin/id | /usr/bin/cut -c1-5`" != "uid=0" ] ; then
echo "You must be the root user to run `basename $0`."
exit 1
fi
# variables
BOOTADM=`which bootadm`
MAILX=`which mailx`
HOST=`hostname`
CAT=`which cat`
RM=`which rm`
RECPT="you@company.com"
# JFYI generates list of boot archive files
# ===============================================
${BOOTADM} list-archive -v > /tmp/archive-list.$$
if [ "$?" -ne "0" ] ; then
${MAILX} -s "Cannot generate boot archive list on ${HOST} - check this manually" ${RECPT}
exit 1
fi
# update boot archive list
# =========================
${BOOTADM} update-archive -v > /tmp/update-archive-result.$$
if [ "$?" -ne "0" ] ; then
${MAILX} -s "Cannot update boot archive on ${HOST} - check this manually" ${RECPT}
exit 1
fi
# Insert text as first/second line in temp files
sed '1i\
Archive Boot List' /tmp/archive-list.$$ > /tmp/archive-list1.$$ ; mv /tmp/archive-list1.$$ /tmp/archive-list.$$
sed '2i\
================ ' /tmp/archive-list.$$ > /tmp/archive-list1.$$ ; mv /tmp/archive-list1.$$ /tmp/archive-list.$$
# Insert dividing ++++++++++
sed '1i\
++++++++++++++++++++' /tmp/update-archive-result.$$ > /tmp/update-archive-result1.$$ ; \
mv /tmp/update-archive-result1.$$ /tmp/update-archive-result.$$
sed '2i\
Update Archive result' /tmp/update-archive-result.$$ > /tmp/update-archive-result1.$$ ; \
mv /tmp/update-archive-result1.$$ /tmp/update-archive-result.$$
sed '3i\
=============== ' /tmp/update-archive-result.$$ > /tmp/update-archive-result1.$$ ; \
mv /tmp/update-archive-result1.$$ /tmp/update-archive-result.$$
# merge 2 temp files in order to email them
# ==============================================
${CAT} /tmp/archive-list.$$ /tmp/update-archive-result.$$ > /tmp/emailfile.$$ || \
echo "Cannot merge 2 temp files about boot archive update"
# send email about successful update
# ===================================
${CAT} /tmp/emailfile.$$ | ${MAILX} -s "Update of boot archive on ${HOST} is successful" ${RECPT} || \
echo "Cannot send email about successful boot archive update"
# remove temp files
# =======================
${RM} /tmp/emailfile.$$ /tmp/archive-list.$$ /tmp/update-archive-result.$$ \
|| echo "Cannot remove temp file /tmp/emailfile.$$"
exit 0
|