Scripting Promise Utility Media Patrol

Promise describes Media Patrol as a routine maintenance procedure that searches the physical drives in a Promise Pegasus unit for media errors. If you’ve got a spare drive in the array, Media Patrol can invoke Predictive Data Migration if it encounters a critical error. This seems like a pretty good idea and something we should schedule.

While the Promise Utility app provides lots of functionality, it requires a running console (you need to be logged in) for some of its functions, like the Scheduler, to run. If you log out, you’ll find the Scheduler and any attendant Background Activities will stop running. This is…sub-optimal. So we’ll work around it using promiseutil.

# Runs Promise Media Patrol on a Pegasus2, logs  the run
# Author: AB @ Modest Industries
# Requires Promise Utility for Pegasus2 (, tested with v3.18.0000.18
# Edit History
# 2014-07-19 - AB: Version 1.0.

export DATESTAMP=`date +%Y-%m-%d\ %H:%M:%S`

# Start / finish messages
start_msg="Promise Media Patrol running..."
finish_msg="Promise Media Patrol complete!"

# Promise Pegasus command line utility default path

# ----------------- Check for promiseutil & set up temp files ------------------
if [ ! -f $promiseutil_path ]; then
        echo "$0 ERROR: $promiseutil_path does not exist"
        echo  "Please download and install the Promise Pegasus Utility app from"
        exit 1

unit_ID_tmp=`mktemp -q "/tmp/$_unit_ID.XXXX"`
if [ $? -ne 0 ]; then
        echo "$0: ERROR: Can't create temp file, exiting..."
        exit 1

# ----------------- Run promiseutil, evaluate the results ------------------

# Get Unit ID information for this Promise unit. Includes workaround for promiseutil tty issue.
screen -D -m sh -c "$promiseutil_path -C subsys -v >$unit_ID_tmp"

# Drop the output into a variable.

# ----------------- Build the message_body ------------------

# If there's a problem, build the header.
if [ "$smart_error_flag" ==  "true" ] || [ "$ata_error_flag" == "true" ]; then

        # SMART Health status.
        if [ "$smart_error_flag" == "true" ]; then
                message_body="$message_body\nSMART Health Status is reporting one or more bad drives."

        # Always include the smart_status

        # Then the ATA errors.
        if [ "$ata_error_flag" == "true" ]; then
                message_body="$message_body\n\nOne or more drives has an ATA Error Count and may be failing.\n\n$ata_errors"

#  ----------------- Logging & email ------------------

# Log the results, conditionally send email on failure.
if [ "$ata_error_flag" == "true" ] || [ "$smart_error_flag" == "true" ]; then
        echo "$DATESTAMP: \n\n$message_body" >> /var/log/system.log
        if [ "$send_email_alert" == "true" ] ; then
                "$sendemail_path" -f $alert_sender -t $alert_recipient -u $alert_subject -m "$message_body" -s $alert_smtp_server
        echo "$DATESTAMP: $pass_msg\n\n$unit_ID" >> /var/log/system.log

# ----------------- Cleanup ------------------

rm -f rm -f $unit_ID_tmp $smart_results_tmp

Using your scheduler of choice (cron, launchd), create a schedule for your script (we’re running it every two weeks across a weekend, when activity on the network is light) and you’re done.