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...

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.

  1. Logon to the Service Console as ROOT
  2. Create a cron configuration file in ROOT’s home directory with

    nano -w crontab

  3. 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

  4. Save the contab file…
  5. 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
     

  6. Restart the crond service with:

    service crond restart

 

This was last published in September 2005

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchServerVirtualization

SearchVirtualDesktop

SearchDataCenter

SearchCloudComputing

Close