V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
moneycwq
V2EX  ›  Windows

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

  •  
  •   moneycwq · 2020-01-23 22:28:12 +08:00 · 2135 次点击
    这是一个创建于 1526 天前的主题,其中的信息可能已经有所发展或是发生改变。

    我使用 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 [email protected]"

    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

    1 条回复    2020-01-23 22:30:56 +08:00
    moneycwq
        1
    moneycwq  
    OP
       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 [email protected]"
    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}"
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1046 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 19:08 · PVG 03:08 · LAX 12:08 · JFK 15:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.