Skip to content

Instantly share code, notes, and snippets.

@lgelo
Last active August 29, 2015 13:57
Show Gist options
  • Save lgelo/9418550 to your computer and use it in GitHub Desktop.
Save lgelo/9418550 to your computer and use it in GitHub Desktop.
LSI Battery Backup Unit (BBU) Autolearn status
#!/usr/bin/env bash
abort() { echo -e "\nERROR: $1" >&2; exit 1; }
usage() { echo -e "\nUsage:\n$0 [-h] | [-s on|off] [-a <adapter>]\n"; exit 0; }
if [ "$(whoami)" != root ] ; then
abort 'Please run this script as root.'
fi
MEGACLI=$(which megacli) || abort 'megacli not found in the path.'
ADAPTER=0
while getopts ":hs:a:" opt; do
case $opt in
h) usage ;;
a) ADAPTER=$OPTARG ;;
s) if [ "$OPTARG" = "on" ]; then
LEARN=0
elif [ "$OPTARG" = "off" ]; then
LEARN=1
else
abort "Wrong parameter $OPTARG"
fi
TMPFILE=$(mktemp -p /tmp bbu.relearn.XXXXXXXXXX) || abort 'Cannot create temp file.'
echo "autoLearnMode=$LEARN" > $TMPFILE
$MEGACLI -AdpBbuCmd -SetBbuProperties -f$TMPFILE -a${ADAPTER} -NoLog >/dev/null
rm -f $TMPFILE
;;
\?) abort "Invalid option -$OPTARG" ;;
:) abort "Option -$OPTARG requires an argument." ;;
esac
done
$MEGACLI -AdpBbuCmd -GetBbuProperties -a${ADAPTER} -NoLog | grep "Auto-Learn Mode"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment