bash 在 vmware 上执行的脚本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22322590/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
script to execute on vmware
提问by user3331975
VMware ESXi systems provide a shell with specific commands like esxcli and works only on those nodes. I want to write a script to read the system IP from a file, login each system and execute the command esxcli network ip get
.
VMware ESXi 系统提供带有特定命令(如 esxcli)的 shell,并且仅适用于这些节点。我想编写一个脚本从文件中读取系统IP,登录每个系统并执行命令esxcli network ip get
。
When I execute the script, that returns "command not found" error:
当我执行脚本时,返回“找不到命令”错误:
> "./snmp.sh: line 3: esxcli: command not found
Is there a way to fix this? The script is as below:
有没有办法来解决这个问题?脚本如下:
#!/bin/bash
while read host; do
ssh -n root@$host esxcli network ip get
done < esxi.txt
回答by peterh - Reinstate Monica
exscli
isn't in your PATH on the esxi server. Simplest fix is to use it with its full path (f.e. /usr/bin/esxcli
). You can find the valid path of the esxcli command on the esxi server with the command which esxcli
.
exscli
不在 esxi 服务器上的 PATH 中。最简单的解决方法是使用它的完整路径 (fe /usr/bin/esxcli
)。您可以使用命令在 esxi 服务器上找到 esxcli 命令的有效路径which esxcli
。
回答by Nimitack
You can run scripts in ESXI with shell.
您可以使用 shell 在 ESXI 中运行脚本。
#!/bin/sh
echo "some vms:"
vim-cmd vmsvc/getallvms
And save it as "something.sh".
并将其另存为“something.sh”。
There are some difference with shell and bash,
shell 和 bash 有一些区别,
Some info here about shell.and more info about the difference here.
这里有一些关于 shell 的信息。以及有关此处差异的更多信息。