Friday, 21 September 2012

Script - BE patching script

If you've read the previous blogs for the u10 BE patching process you'll know it is a bit long winded - so I've tried my hand a little bash scripting. It has been tried out on a test box and it works.....

The error handling isn't exactly what I want and therefore the script will be subject to change.

u10 upgrade script (updater)

#!/usr/bin/ksh
# Bash script for Solaris patching
# To be stored in /usr/local/sbin for Systems Administrator

# Prior to running script make sure enough free space is available on the target server.
# Enough space is required for:
# Patch bundle - 2Gb
# Extracted patch bundle - 4Gb
# BE patches - 20Mb
# New boot environment - 6Gb

clear
df -h
sleep 5

# Mount the NFS patch area
clear
if mount | grep /mp > /dev/null; then
    echo "/mp already mounted"
    sleep 3
    else
    if [ -d "/mp" ]; then
        mount -F nfs <mount_point> /mp  || { echo "Mount command failed"; sleep 3; exit 1; }
        echo "mounted sol_nfs_patch"
        sleep 3
        else
        mkdir /mp || { echo "Create /mp directory failed"; sleep 3; exit 1; }
        mount -F nfs <mount_point> /mp || { echo "Mount command failed"; sleep 3; exit 1; }
        echo "created /mp and mounted sol_nfs_patch"
        sleep 3
    fi
fi

clear
# check if /cpu folder exists, if not create
if [ -d "/cpu" ]; then
    echo "/cpu directory already exists"
    sleep 3
    else
    mkdir /cpu  || { echo "create /cpu failed"; sleep 3; exit 1; }
    echo "created directory /cpu"
    sleep 3
fi

clear
# Choose from available patches
ls /mp/cpu
echo "Choose a CPU: "
read CPU
clear
echo "$CPU is the file you have chosen"

clear
# Copy recommended zip file over to /cpu
if [ -f "/cpu/$CPU" ]; then
    echo "File already exists in /cpu"
    sleep 3
    else
    echo "Copying $CPU to /cpu"
    cp /mp/cpu/$CPU /cpu || { echo "Failed to copy $CPU file"; sleep 3; exit 1; }
    echo "Copied $CPU file to /cpu"
    sleep 3
fi

# unzip the CPU file
cd /cpu
unzip /cpu/$CPU || { echo "Failed to unzip $CPU file"; sleep 3; exit 1; }

# free space up on local server by removing zip file
if [ ! -f "/cpu/$CPU" ]; then
    echo "$CPU file not found"  
    sleep 3
    else
    cd /cpu
    rm $CPU || { echo "Unable to delete $CPU"; sleep 3; exit 1; }
    echo "$CPU file removed"
    sleep 3
fi

# The unzipped directory is
UDIR=$(ls -t /cpu | head -1)
echo "Unzipped directory is /cpu/$UDIR"
sleep 3

# Run pre-resquisite patchset install on existing BE
echo "Installing pre-resquisite patchset"
sleep 3
cd /cpu/$UDIR
./installcluster --apply-prereq --s10patchset || { echo "Unable to apply-prereq"; sleep 3; exit 1; }

# Create BE
echo "Creating a new BE called $UDIR"
sleep 3
lucreate -n $UDIR || { echo "Unable to create $UDIR BE"; sleep 3; exit 1; }
lustatus
sleep 3

# patch created BE
echo "Patching $UDIR BE"
sleep 3
luupgrade -n $UDIR -s /cpu/$UDIR/patches/ -t `cat /cpu/$UDIR/patch_order` || { echo "Patch of BE failed"; sleep 3; exit 1; }
echo "Script finished"
sleep 3
exit 0

No comments:

Post a Comment