Using Cron to automate reboot/shutdown of ESX
How to shutdown/reboot the ESX server at designated time.
This week I looked briefly at automating repetitive tasks with the CRON Utility. In this case, I wanted to shutdown/reboot...
Continue Reading This Article
Enjoy this article as well as all of our content, including E-Guides, news, tips and more.
the ESX server at a designated time. This was used in conjunction with ESX’s ability to automatically start-up and shutdown VMs.
Crond is a service which is used to schedule scripts of hourly/daily/weekly/monthly events. VMware utilizes this to run their own scripts, which can be seen in /etc/cron.daily, /etc/hourly and so on. Cron can also handle events such as: on reboot run this script with its @reboot syntax Along side these system-wide cron configurations you can also have per-user cron configurations. In my example, I’m using a per-user cron configuration to shutdown my servers at 9.30pm every evening. My development environment is accessible to some people – but due to physical limitations I cannot run my servers 24/7. So I need them to start-up in the morning and shut down in the evening.
- Logon to the Service Console as ROOT
- Create a cron configuration file in ROOT’s home directory with
nano -w crontab
- Type in this configuration:
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/# run-parts
30 21 * * * shutdown -h now
Note:
The path statements allow cron to find the shutdown utility which is held in /sbin. The command shutdown -h now causes ESX to do a full shutdown. The -h forces a halt which stops the swap file and un-mounts the drives. 30 21 is 9:30pm…For more information about setting the time value see this link
- Save the contab file…
- Register this configuration file with crontab with:
crontrab /root/crontab
Note:
Confirm this has been registered with crond by listing the crontabs for root with:crontab -l
If you wish to remove a scheduled event use:crontab -r
- Restart the crond service with:
service crond restart