Schedule Shutdown Esxi (v5)

This script would be using two commands available on the esxi.

  • /sbin/powerOffVms (Stop the current's running vms)
  • /bin/poweroff (Stop the Esx host)

I have called it:
 #! /bin/ash
 echo "shutting down VMs..please wait.."
 echo "done."
 echo "shutting down the host now.."


Apply the execution's rights :

chmod +x /vmfs/volumes/datastore1/


Add this script in /etc/rc.local

/bin/echo "0 22 * * * /vmfs/volumes/datastore1/" >> /var/spool/cron/crontabs/root

This script would stop the vms and the Esxi host everyday at 22h.


On Esxi Version 5.1, editing /etc/rc.local is no longer valid and you need to use /etc/rc.local.d/ instead.

V5.1, add the line into /etc/rc.local.d/

You may also like...

11 Responses

  1. Juan Carlos Ch says:

    Hi thanks excellent guide!!! I have a problem, i need edit this script but i can’t.
    I use the ” VI root” command but it appears readonly and when parameters change but i can’t save and exit.

    • nicolas says:


      Can you provide the entire command, which include even the path in which the script to reside?

  2. Rashmi says:

    How do I schedule my Ubuntu VM to shutdown at 2:30am everyday and then shutdown my esxi host after that? Can you provide step by step instructions I’m really new to esxi. I am running esxi 6. Also will my schedule be saved after restart?


    • nicolas says:


      You should/might add this command vim-cmd vmsvc/power.shutdown ID into the crontab of your Esx(i).
      However, you would require to figure the ID of your current vm located to your esxi.
      USing esxcli vm process list should list upon machine name the vm id.

      Much more details on :

      Hope that would help,

      • Pintu says:

        Where exactly would I put this (what location) and do I just copy and paste it?:

        vim-cmd vmsvc/power.shutdown ID


        • nicolas says:

          Hi There,

          The location of the script is up to you; However as mentioned in the article, I was taking one of the datastore location such as : /vmfs/volumes/datastore1/

          • Pintu says:

            Thanks, here is the issue I am running into:

            when I run the vim-cmd vmsvc/power.shutdown ID from the command line it works fine to shutdown my VMs but when the time in file occurs, none of the script is working. My 2 VMs don’t shutdown and also the ESXI host doesn’t turn off either. How can I fix this?

            here is my script in the same location as yours:

            #! /bin/ash
            echo “shutting down VMs..please wait..”
            vim-cmd vmsvc/power.shutdown 4
            vim-cmd vmsvc/power.shutdown 6
            echo “done.”
            echo “shutting down the host now..”

            and here is my timer:

            /bin/echo “18 14 * * * /vmfs/volumes/567b3d33-386ac406-f464-00259002091e/” >> /var/spool/cron/crontabs/root

            Am I supposed to change anything in the crontabs/root location?


          • nicolas says:

            Hi There,

            Does the script works as when you run it manually?

            If yes, this might means that the crontab does not take care of it at the time scheduled.
            If no, commnent the line /sbin/poweroff (avoiding to get the esx poweroff.) then you might add “-x” after #!/bin/ash
            so the first line would become : #!/bin/ash -x
            then try to run it manually, you would see from the console everything step by step.

            I am suspecting issue with the path for each vim-cmd (default: /bin/vim-cmd)

            Let me know,

  3. fun party says:

    Excellent article. I definitely appreciate this website.
    Keep it up!

  4. Not_an_expert says:

    On my ESXi 5.0 host /bin/poweroff doesn’t work from the Crontab file (/var/spool/cron/crontabs/root), neither does the echo command (/bin/echo and /sbin/echo). All of these are symlinks to /bin/busybox. I suspect that these symlinks are not defined in the environment used by Crontab. However, using the command /bin/busybox poweroff in the Crontab file does work.

    • nicolas says:

      Hi there,

      Indeed, this is link as the /bin/poweroff to /usr/lib/vmware/busybox/bin/busybox
      lrwxrwxrwx 1 root root 35 Nov 23 10:03 poweroff -> /usr/lib/vmware/busybox/bin/busybox

      However, calling the symbolic link should be fine.
      Thank you for your input btw.


Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>