Skip to content

Instantly share code, notes, and snippets.

@KhasMek
Created January 26, 2014 07:49
Show Gist options
  • Save KhasMek/8629794 to your computer and use it in GitHub Desktop.
Save KhasMek/8629794 to your computer and use it in GitHub Desktop.
BASH: list ESXi disks
#!/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.
drives="esxi_drive_listing"
command="esxcli storage core device smart get -d"
time=`date +"%D @ %r"`
title="TITLE HERE"
filename="temp_name"
email="fuu@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'`
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
echo "[ $status @ $temp °F ] $disk_name ($disk_id)" >> "$filename"_error
fi
echo "[ $status @ $temp °F ] $disk_name ($disk_id)"
fi
done
echo ""
} > "$filename"
hour=`date +%H`
# Use 24 hour format for hours
start_normal_hours=8
end_normal_hours=18
if [ $hour -ge $start_normal_hours ] && [ $hour -lt $end_normal_hours ]; then
mail -s \"Status\ Update\" -v "$email" < "$filename"
else
mail -s \"Status\ Update\" -v "$email" < "$filename"_error
fi
# Cleanup
rm "$filename" "$filename"_error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment