Skip to content

Instantly share code, notes, and snippets.

@scar45
Forked from KhasMek/exsi_disk_status.sh
Last active August 29, 2015 13:55
Show Gist options
  • Save scar45/8777740 to your computer and use it in GitHub Desktop.
Save scar45/8777740 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Quickly display the output from various ESXi disks.
# Until I get feedback, this is going to be a dirty to write it. Should work?
#
# File syntax for the drive listing should look something like this -
# DRIVE NAME = DRIVE ID
# The '=' is important as that's the sepperator for the variables.
while true
do
drives="esxi_drive_listing"
command="esxcli storage core device smart get -d"
time=`date +"%D @ %r"`
title="PRT-ESXi Disk Health Status Report:"
filename="report_log"
email="foo@bar.net"
echo ""
echo "$title"
echo ""
echo "Time of S.M.A.R.T. analysis: $time"
echo ""
cat "$drives" | while read line; do
disk_name=`echo "$line" | cut -f1 -d "="`
disk_id=`echo "$line" | cut -f2 -d "=" | sed 's/^ *//g'`
status=`eval "$command $disk_id" | grep "Health" | awk {'print $3'}`
temp=`eval "$command $disk_id" | grep "Drive Temperature" | awk {'print $3'}`
drive=`echo "$line" | cut -f1 -d " "`
echo "[ $status @ $temp °F ] $disk_name ($disk_id)"
done
echo ""
{
echo ""
echo "$title"
echo ""
echo "Time of S.M.A.R.T. analysis: $time"
echo ""
cat "$drives" | while read line; do
disk_name=`echo "$line" | cut -f1 -d "="`
disk_id=`echo "$line" | cut -f2 -d "=" | sed 's/^ *//g'`
if [ "$1" = "-v" ]; then
eval "$command $disk_id"
else
status=`eval "$command $disk_id" | grep "Health" | awk {'print $3'}`
temp=`eval "$command $disk_id" | grep "Drive Temperature" | awk {'print $3'}`
drive=`echo "$line" | cut -f1 -d " "`
# echo "Status of $drive: $status"
if [ "$status" != "OK" ]; then
# I had to change the operand from ! to != (unknown operand error)
echo "[ $status @ $temp °F ] $disk_name ($disk_id)" >> "$filename"_error
fi
echo "[ $status @ $temp °F ] $disk_name ($disk_id)"
fi
done
echo ""
} > "$filename"
# TODO: If the status ! 'OK' then email specified address
# Maybe if the run time is after 6pm (or something- business hours) then
# the script will only email results if there is a warning?
# mail -s \"Status\ Update\" -v "$email" < "$filename"
# mail -s \"Status\ Update\" -v "$email" < "$filename"_error
# scar45: I have disabled the mail function since ESXi doesn't have the ability (mail: not found)
# Hoping to have this loop on a timer (w/a way to force exit?) since CRON isn't as useful
# without the e-mail functionality. I'll just open a PuTTY session and run the script once
# then leave the terminal window open and monitor that way (for nao)...
# also, if all Status == "OK", then the error file doesn't get created, and below, the 'rm' command errors w/404 ;)
# Cleanup
# rm "$filename" "$filename"_error
# Loop counter in seconds (CTRL+C to break)
sleep 900
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment