pintu1228
Contributor
Contributor

Need help setting up crontab for scheduled shutdown

Hi everyone, this is my first post.

i Have been trying to figure out how to have my Ubuntu VM turn off at 1:00 AM every night followed by turning off ESXi host.  Then i want my ESXI host to turn on at 8:00 AM.  The reason for nightly shutodwn this mainly acts as a media server and doesnt need to be on all night.

i Have been trying to figure this out with many examples but can't figure how to do this.  if someone can provide steps on exactly how to accomplish this on ESXI 6.5, i wo be grateful.

I have tried creating a script but don't think I did it correctly.

thanks in advance

Tags (2)
0 Kudos
7 Replies
MattiasN81
Hot Shot
Hot Shot

The best way to accomplish this is via vSphere CLI, you need a Windows or Linux machine for this or you can also use the vSphere Management Appliance (free product)

1. create a cronjob or a scheduled task on the Windows/Linux client with this command "vicfg-hostops.pl" -a poweroff -f --server=ESXIHOSTNAME/IP --username root --password YOUR PASSWORD--operation shutdown"

2. Enable Autostart option on the ESXi

esxi_auto.GIF

This will allow the VMs to shutdown and start with the host.

To power on the ESXi you need to use wake-on-lan or a server with an out of band management controller

VMware Certified Professional 6 - DCV VMware VTSP Software Defined Storage Dell Blade Server Solutions - EMEA Certified Dell PowerEdge Server Solutions - EMEA Certfied Dell Certified Storage Deployment Professional Dell EMC Proven Professional If you found my answers useful please consider marking them as Helpful or Correct
0 Kudos
pintu1228
Contributor
Contributor

Thanks for the quick reply, just a few more questions.

1.  If I decide to run on Windows/Linux, can I used my Windows 10 PC?  Or do I need to install windows/linux on the ESXI host?  Does the Windows/Linux need to be on all the time in order to run the command?

2.  Which version of Linux should I install on my Esxi host to carry out the nightly shutdown tasks?

3.  How do I go about creating crontab or scheduled task in Vspehere Management Appliance and Windows/Linux?  From the command below, it seems that it doesn't specify what time to turn off host, so if you can provide exactly what I need to do, that would be great.

4.  When the command runs, does it start initiating shutdown of host or VMs followed by host?

5.  To power on the ESXi you need to use wake-on-lan or a server with an out of band management controller----I have wake-on-lan enabled on my motherboard, so how do I schedule this to wake up esxi host everyday at 8:00 AM?  I have tried to send the wake-on-lan packets from my Egdemax router but it doesn't seems to do anything.

Thanks for your help.

0 Kudos
MattiasN81
Hot Shot
Hot Shot

1. Yes, you can use any PC you like as long you have VMware CLI installed on it, Windows, Linux dosen't matter, vSphere CLI is available for both platforms

vSphere CLI for vSphere 6.5 - VMware {code}

2. Any distribution of Linux or Windows, matter of taste

3. The  command is just the shutdown command, you need to create a scheduled task in Windows, or a cronjob in Linux that run the command on the time of your choosing

Windows: https://technet.microsoft.com/en-us/library/cc748993(v=ws.11).aspx

Linux: https://www.cyberciti.biz/faq/how-do-i-add-jobs-to-cron-under-linux-or-unix-oses/

4. Is starts with the host and the host sends a shutdown command to the VMs, if the host recives a heartbeat from VMware tools it will bring down the VM gracefully, otherwise it will just power them down.

5. Well, that depends on your router, or the client that sends the WOL package if it have support to shedule it.

WOL is pretty crappy and work when it wants to, but is the only thing available for the consumer market.

If you want a more reliable solution i suggest you take a look on a cheap server, Supermicro for example with an BMC/Lights-Out controller, those have the ability to power on on schedule by themselves.

VMware Certified Professional 6 - DCV VMware VTSP Software Defined Storage Dell Blade Server Solutions - EMEA Certified Dell PowerEdge Server Solutions - EMEA Certfied Dell Certified Storage Deployment Professional Dell EMC Proven Professional If you found my answers useful please consider marking them as Helpful or Correct
0 Kudos
pintu1228
Contributor
Contributor

Thanks but still can't seem to figure out this.

Here is what I have done:

I have installed a Windows Server 2012 R2 vm on the Esxi host to run the powershell command and a scirpt (have attached it below).

12.JPG

As you can see I put the program to run as powershell and the arguments as: -ExecutionPolicy Bypass C:\Users\Administrator\Desktop\shutdown.ps1

But task never runs.  Is there something wrong with my script?

0 Kudos
MattiasN81
Hot Shot
Hot Shot

‌The script you provided isnt written in PowerShell, its a shell script written for esxi.

To use this script you need to tun it directly on the esxi

VMware Certified Professional 6 - DCV VMware VTSP Software Defined Storage Dell Blade Server Solutions - EMEA Certified Dell PowerEdge Server Solutions - EMEA Certfied Dell Certified Storage Deployment Professional Dell EMC Proven Professional If you found my answers useful please consider marking them as Helpful or Correct
0 Kudos
pintu1228
Contributor
Contributor

Thanks,

can you provide with a script I can use to run in Task Scheduler?  I have been trying to figure out how to do nightly shutdown of VM's and Esxi host for a few months but can't seem to figure it out.

If you think its better to do cronjob in Esxi host, then can you provide steps on how to do that exactly.  I am open to suggestion but just want to figure this out.

Thanks again

0 Kudos
MattiasN81
Hot Shot
Hot Shot

‌I did provide a oneliner you can use in task scheduler, see my first post in this thread

VMware Certified Professional 6 - DCV VMware VTSP Software Defined Storage Dell Blade Server Solutions - EMEA Certified Dell PowerEdge Server Solutions - EMEA Certfied Dell Certified Storage Deployment Professional Dell EMC Proven Professional If you found my answers useful please consider marking them as Helpful or Correct
0 Kudos