OpenWrt | Automatic SSH to ESXi server to issue power down

I have a home ESXi server that is on 24/7. This wasn't previously a problem, but with UK electricity costs scheduled to increase to 52p per kW/h, I'd like to set up a schedule to automatically power down the server when not in use.

It is a Dell T3610 workstation and has the option for 'power recovery' or 'scheduled power on'. That gives me the choice of using a smart plug to power it on or I can simply set a schedule in the BIOS.

Shutting down the machine is more complex. ESXi doesn't include a power-off scheduling feature.

Is it possible, maybe via a package, to have OpenWrt SSH to the ESXi server, authenticate and then issue the shutdown command?

The only VM that I'm currently running is Windows Server 2019 and I only need it to be powered on between 6pm and midnight. I can use Task Scheduler to shut down the Windows VM each evening and then power down the ESXi host ten minutes later.

Any ideas on the best way to achieve this?


What do you think about SSH key based authentication and a cron job running
ssh ESXi_user@ESXi_IP_address "/sbin/ && /sbin/poweroff" ?

You could schedule it in the esxi crontab

I can't get putty to authenticate via an ssh key.

Server refused our key

This also looks promising, but vsphere CLI has been deprecated. I have installed the new solution esxicli, but I don't have a clue how to use it or create the scheduled task.

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 

"" -a poweroff -f --server=***ESXIHOSTNAME/IP*** --username ***root*** --password ***YOUR PASSWORD***--operation shutdown"

You have the openwrt sshpass package. Look at the man on how to use it

OK. That looks like a promising way to log into the server.

How do I then pass the shutdown command via the CLI?

This is really outside my skillset. If anybody can hold my hand to get this working, I'd really appreciate it.

Did you read the link I posted about crontab on esxi?

If you ssh to the esxi host and run the following, do the VMs shut down and then the host?

/sbin/ && /sbin/poweroff


Thanks for taking the time to reply. I have achieved it via a cron job on the ESXi server.

Please note that this guide uses incorrect syntax for the file - it should be " instead of '. My first attempt resulted in the directory structure being written to the cron file.

Shell script saved in this folder.


File contains:


Cron file updated - /var/spool/cron/crontabs/root

#min hour day mon dow command
1    1    *   *   *   /sbin/
1    *    *   *   *   /sbin/ ++group=host/vim/vmvisor/
0    *    *   *   *   /usr/lib/vmware/vmksummary/
*/5  *    *   *   *   /bin/ ++group=host/vim/vmvisor/hostd-probe/stats/sh
00   1    *   *   *   localcli storage core device purge
*/10 *    *   *   *   /bin/crx-cli gc
00 0 * * * /vmfs/volumes/datastore1/ file updated to write new cron job to cron file at boot /etc/rc.local.d/

/bin/kill $(cat /var/run/
/bin/echo "00 0 * * * /vmfs/volumes/datastore1/" >> /var/spool/cron/crontabs/root

Changes saved.

Server now reboots with a persistent cron job that is set to run at midnight.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.