Hello,
I have the following script I'm working on. Its purpose is to gracefully shutdown critical VM's in case I need to perform work... one script to rule them all.
#! /bin/ash
echo "=================================================="
echo "Gracefully shutting down critical virtual machines"
echo "=================================================="
echo
if [ "$HOSTNAME" == "esx01" ]; then
echo "Shutting down VMs on ESX01"
vim-cmd vmsvc/power.shutdown 4816
vim-cmd vmsvc/power.shutdown 5456
vim-cmd vmsvc/power.shutdown 3392
vim-cmd vmsvc/power.shutdown 5248
vim-cmd vmsvc/power.shutdown 6000
echo "Done."
elif [ "$HOSTNAME" == "esx02" ]; then
echo "Shutting down VMs on ESX02..."
vim-cmd vmsvc/power.shutdown 352
vim-cmd vmsvc/power.shutdown 368
vim-cmd vmsvc/power.shutdown 512
vim-cmd vmsvc/power.shutdown 528
vim-cmd vmsvc/power.shutdown 592
echo "Done."
else
echo "No machines were shutdown."
fi
I had thought that $HOSTNAME was the environment variable with the name of the host server. Evidently, this isn't the case.
How can I determine the HOSTNAME so I can have one script that would be able to be used on several servers to shutdown the proper VM's?
Thanks,
Johnathan