求助,如何虚拟机 windows 使用 apc PowerChute Business Edition 软件关闭 esxi 主机?

2020-01-23 22:28:12 +08:00
 moneycwq

我使用 esxi 虚拟的 windows 2019 运行 apc PowerChute Business Edition,可以识别到 ups,该软件可以在断电后启动一个批处理命令,但是这个批处理不能进行桌面交互。我在 esxi 主机里做了一个 sh,我想通过 cmd 模式的 ssh 链接 esxi 主机,运行这个 sh,这个 sh 批处理关闭主机下的全部虚拟机,最后在关闭 esxi。为此做了一个 vbs 来完成,自动 ssh 链接 esxi 主机,自动启用 sh。单独点击这个 vbs 都可以完成任务,但是通过 apc PowerChute Business Edition 的软件启动批处理就无法运行。很困惑。不知道哪位可以指点迷津,让我可以在断电后自动关闭全部虚拟机,并关闭 esxi 主机。 ssh 使用 openssh,vbs 我这样写的,不知道对不对。是不是必须要编写成批处理才可以?但是我不懂 cmd 模式下的批处理,不知道怎么编写。希望得到帮助,谢谢

我写的 vbs Dim WshShell

Set WshShell=WScript.CreateObject("WScript.Shell")

WshShell.Run "cmd.exe"

WScript.Sleep 1500

WshShell.SendKeys "ssh root@192.168.1.11"

WshShell.SendKeys "{ENTER}"

WScript.Sleep 1500

WshShell.SendKeys "12345678"

WshShell.SendKeys "{ENTER}"

WScript.Sleep 1500

WshShell.SendKeys "cd /vmfs/volumes/datastore/UPS"

WshShell.SendKeys "{ENTER}"

WScript.Sleep 1500

WshShell.SendKeys "sh test.sh"

WshShell.SendKeys "{ENTER}"

apc 自己带的一个默认的 cmd 文件里面解释如下: rem This command file provides examples of proper command file syntax

rem 此命令文件提供了正确的命令文件规则的范例

rem Command Files run by PowerChute Business Edition must be placed in this directory.

rem 运行 PowerChute Business Edition 的命令文件必须放在此文件目录下

rem Use the full path name of executable programs and external command files.

rem 请采用可执行文件和外部命令文件名称(含所有目录路径)

rem The @START command must be used to run executable programs (see example below).

rem @START 开始命令必须用于运行可执行文件(如下所示)

rem For the @START command, path names that include spaces must be enclosed in quotes;

rem arguments for the executable must be outside the quotes. A double quote must

rem precede the quoted path name. For example, to execute a command file in

rem c:\Program Files\APC\PowerChute Business Edition\agent\cmdfiles called myShut.exe,

rem the following line should be entered in the command file:

rem 对于 @START 开始命令, 有空格的路径名称必须包含在引用内,可执行的必须放到引用外.

rem 双重引用必须优先于引用路径名称,例如,运行 c:\Program Files\APC\PowerChute Business Edition\agent\cmdfiles 目录下的命令文件 myShut.exe

rem 以下行应输入到命令文件中

rem @START "" "c:\Program Files\APC\PowerChute Business Edition\agent\cmdfiles\myShut.exe"

rem time /T >> C:\apctest\cmdtest.txt

2153 次点击
所在节点    Windows
1 条回复
moneycwq
2020-01-23 22:30:56 +08:00
排版问题,我单独写一下写的 vbs 内容
Dim WshShell
Set WshShell=WScript.CreateObject("WScript.Shell")
WshShell.Run "cmd.exe"
WScript.Sleep 1500
WshShell.SendKeys "ssh root@192.168.1.21"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 1500
WshShell.SendKeys "CHENyyrui*102437"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 1500
WshShell.SendKeys "cd /vmfs/volumes/datastore/UPS"
WshShell.SendKeys "{ENTER}"
WScript.Sleep 1500
WshShell.SendKeys "sh test.sh"
WshShell.SendKeys "{ENTER}"

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/640093

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX