Created
October 8, 2014 04:57
-
-
Save sagunms/277e7317c9927b986500 to your computer and use it in GitHub Desktop.
Automatically power on servers if PoweredOff in VMware ESXi 5.0
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
First time configuration | |
vi /var/spool/cron/crontabs/root | |
0 */15 * * * /vmfs/volumes/datastore1/auto-poweron.sh | |
vi /vmfs/volumes/datastore1/auto-poweron.sh | |
VMS=$(vim-cmd vmsvc/getallvms | grep -v Vmid | awk '{print $1}') | |
for VM in $VMS ; do | |
PWR=$(vim-cmd vmsvc/power.getstate "$VM" | grep "Powered") | |
if [ "$PWR" == "Powered off" ] ; then | |
vim-cmd vmsvc/power.on $VM | |
fi | |
done | |
chmod 775 /vmfs/volumes/datastore1/auto-poweron.sh | |
kill `cat /var/run/crond.pid` | |
## For persistent crontab (when OVH server restarts) | |
vi /etc/rc.local | |
/bin/kill $(cat /var/run/crond.pid) | |
/bin/echo '0 */15 * * * /vmfs/volumes/datastore1/auto-poweron.sh' >> /var/spool/cron/crontabs/root | |
crond | |
## Restart cron daemon | |
busybox crond | |
cd /vmfs/volumes/datastore1/ | |
./auto-poweron.sh | |
# To Edit the Crontab next time # | |
kill `cat /var/run/crond.pid` | |
vi /var/spool/cron/crontabs/root | |
busybox crond |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment