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 first published in September 2005

Dig deeper on VMware ESX and ESXi administrative tips

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

SearchServerVirtualization

SearchVirtualDesktop

SearchDataCenter

SearchCloudComputing

Close