Vmware Tools works with shell scripts to automatically shut down the ESXI6.0 process

Source: Internet
Author: User


Vmware Tools works with shell scripts to automatically shut down the ESXI6.0 process

Prerequisites: Each virtual server in the ESXi host needs to install the VMware Tools tool and use it with the script, otherwise it will not be able to shut down properly.

Install VMware Tools:

650) this.width=650; "src=" https://s4.51cto.com/oss/201710/26/afa2a2b33765c7200df1ab2bd173eb92.jpg "style=" float: none; "title=" 1.jpg "alt=" Afa2a2b33765c7200df1ab2bd173eb92.jpg "/>

650) this.width=650; "src=" https://s1.51cto.com/oss/201710/26/0e9886bef0bb8ee6418e132675da288f.jpg "style=" float: none; "title=" 2.jpg "alt=" 0e9886bef0bb8ee6418e132675da288f.jpg "/>

Determine if the VMware Tools tools are installed

Observation from ESXi:

Right-click Observation has been installed:

650) this.width=650; "src=" https://s5.51cto.com/oss/201710/26/462ad78c0b03d1c6209def08193900c5.jpg "style=" float: none; "title=" qq20171026120226.jpg "alt=" 462ad78c0b03d1c6209def08193900c5.jpg "/>

The VMware Tools tool is not installed:

650) this.width=650; "src=" https://s5.51cto.com/oss/201710/26/88caea33578dd74777ce6516635b6f60.jpg "style=" float: none; "title=" qq20171026120320.jpg "alt=" 88caea33578dd74777ce6516635b6f60.jpg "/>

Of course, you can also enter the system to view:

If you have installed a successful system service, you can see the VMware Tools service, such as.

650) this.width=650; "src=" Https://s2.51cto.com/oss/201710/26/9738437712fbc2e7a15a291e2ead3fd4.jpg "title=" Qq20171026121244.jpg "alt=" 9738437712fbc2e7a15a291e2ead3fd4.jpg "/>

Note If VMware Tools is not installed in the virtual server on ESXi

Use the command:

First, Vim-cmd Vmsvc/power.off

Second, esxcli VM process kill-t Soft (hard/force)-W

Shut down the virtual machine, although you can shut down the virtual machine, after repeated testing is forced power off, re-turn on the server will have an abnormal shutdown prompt, and the system log will be recorded.

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/26/1e3fa7e21b65dcad6aa44bc4de641cb8.jpg "title=" Qq20171026120002.jpg "style=" WIDTH:650PX;HEIGHT:516PX; "alt=" 1e3fa7e21b65dcad6aa44bc4de641cb8.jpg "hspace=" 0 " height= "516" width= "650" vspace= "0" border= "0"/>

650) this.width=650; "src=" Https://s4.51cto.com/oss/201710/26/eb2caa018af640cbd625f2c068e20131.jpg "title=" Qq20171025102915.jpg "style=" WIDTH:650PX;HEIGHT:439PX; "alt=" eb2caa018af640cbd625f2c068e20131.jpg "hspace=" 0 " height= "439" width= "650" vspace= "0" border= "0"/>

If you use the: Vim-cmd vmsvc/power.shutdown command to close (without the VMware Tools tool installed) ESXi will have an error message and the command will not be executed successfully.

650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/26/cc33d8cf12018a8e2930bcfbecb9c5f5.jpg "title=" Qq20171025105329.jpg "alt=" Cc33d8cf12018a8e2930bcfbecb9c5f5.jpg "/>

Take a look at the full picture: (Vmware Tools) The difference between installing and not installing

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/26/7640008cf3fefa9b835602344726e255.jpg "title=" Qq20171026114255.jpg "style=" WIDTH:650PX;HEIGHT:516PX; "alt=" 7640008cf3fefa9b835602344726e255.jpg "hspace=" 0 " height= "516" width= "650" vspace= "0" border= "0"/>


Finally, close the script:


#!/bin/sh

#author by Jerry_ Jiang 2017

#正常关闭虚拟服务器及ESXI主机

off= ' esxcli VM process list|grep World |awk ' {print $} ' |wc-l '
Status= ' Vim-cmd/hostsvc/hostsummary | grep inmaintenancemode|cut-c 27 '
if [$off = = 0]; then
[$status = "F"] && vim-cmd hostsvc/maintenance_mode_enter 1&>/dev/null && sleep && Halt | | Halt
Else
hostsum= ' vim-cmd vmsvc/getallvms|awk ' nr>1{print ' |wc-l '
Vim-cmd Vmsvc/getallvms|awk ' Nr>1{print} ' >tmp.txt

For i in ' seq 1 $hostsum '
Do
Vid= ' Sed-n "$i p"./tmp.txt '
On= ' vim-cmd vmsvc/power.getstate $vid |tail-1|awk ' {print $} ' 2&>/dev/null '
if [$on = = On];
Vim-cmd Vmsvc/power.shutdown $vid 1&>/dev/null
Sleep 5
Fi
Done
Rm-rf./tmp.txt
#强制关闭虚拟服务器及ESXI主机
off= ' esxcli VM process list|grep World|awk ' {print $} ' |wc-l '
if [$off = = 0]; then
Vim-cmd Hostsvc/maintenance_mode_enter 1&>/dev/null
Sleep 10
Halt
Else
PS |grep Vmx|awk ' {print $} ' |uniq >tmp.txt
On= ' PS |grep Vmx|awk ' {print $} ' |uniq |wc-l '
For i in ' seq 1 $on '
Do
Hostid= ' Sed-n "$i p"./tmp.txt '
Kill $hostid 1&>/dev/null
Done
Rm-rf./tmp.txt
Vim-cmd Hostsvc/maintenance_mode_enter 1&>/dev/null
Sleep 10
Halt
Fi
Fi

Vmware tools with above shutdown script (Vim-cmd vmsvc/ Power.shutdown) use, shut down the virtual server, do not appear error log prompt, if there is a subsequent forced shutdown script execution (indicating that the virtual server has an exception that caused the failure to shut down properly, so forced to shut down, you can view the virtual server and ESXi log exclusions, there is no discussion, Because the server normally shuts down normally.)

This article comes from "on the road ... Recover lost Memory "blog, declined reprint!"

Vmware Tools works with shell scripts to automatically shut down the ESXI6.0 process

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.