1

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.

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
peterh
  • 11,875
  • 18
  • 85
  • 108
user3331975
  • 2,647
  • 7
  • 28
  • 30

2 Answers2

1

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.

peterh
  • 11,875
  • 18
  • 85
  • 108
  • The issue is not with esxcli not installed or path set on esxi server. When I do manual ssh, login to esxi and execute, that works fine.. however not via script. ~]# ssh root@10.145.7.1 Password: ~ # /usr/bin/esxcli network ip get IPv6Enabled: true ~ # – user3331975 Mar 11 '14 at 10:32
  • 1
    @user3331975 No, you will have another PATH, because it will be a noninteractive shell on the esxi side, and some of the initscripts (partially, setting PATH) aren't called. It is really simple to test: try to run _anything_ from a scripted ssh with full path, and it will work. – peterh Mar 11 '14 at 10:35
0

You can run scripts in ESXI with shell.

#!/bin/sh
echo "some vms:"
vim-cmd vmsvc/getallvms

And save it as "something.sh".

There are some difference with shell and bash,

Some info here about shell. and more info about the difference here.

Community
  • 1
  • 1
Adam Delarosa
  • 901
  • 1
  • 10
  • 20