- 1 Getting In The Shell
- 2 Ninja ESXi Shell Commands
- 3 Thoughts
After writing up a post on “Becoming An ESXi Direct Console User Interface (DCUI) Ninja“, I wanted to follow up with some content that revolves around the ESXi Shell. The details outlined here are meant to serve as a good stepping off point for those who are a curious as to what the ESXi Shell can do, especially for those intimidated by CLI or “Linux like” commands.
While the hope is that you never really have to jump onto the ESXi Shell – typically, this means something has gone wrong – it’s good to have a comfort level and familiarity with how to navigate around in the shell. Additionally, there are still a hefty number of actions that require using the shell in one way or another, either directly on the console of your host, or via vCLI or the vSphere Management Assistant (vMA).
Getting In The Shell
The first step is to access the ESXi Shell. There are a few ways to accomplish this. If the network to the host is not operational, you’ll have to use the Direct Console User Interface (DCUI) to enable the ESXi Shell (see the previous post in this series for details). However, if the host is available on the network, you can switch over to SSH. The easiest way to do this is simply start the service on the host.
Enabling The SSH Daemon (Service)
The first step is to navigate to the security profile of your host. Click “Properties…”
From there, select the SSH service and click the “Options…” button.
Finally, click the “Start” button to start the daemon.
Reaching The Shell From The DCUI
Reaching the ESXi Shell from the DCUI is simple. Once the ESXi Shell is enabled, Press Alt + F1 to reach the ESXi Shell window. To switch back to the DCUI, Press Alt + F2.
Ninja ESXi Shell Commands
Now that you have access to the shell, let’s go over some of the commands I feel you should know without hesitation to get the job done.
The tail command looks at the end of a file, and is my most commonly used tool. Let’s look at what happens when I do:
I see the last several lines of the log. This helps when you are troubleshooting an issue that happened recently.
A really cool arguement for the tail command is -f (follow). This will actively follow the newly written lines and present them on the screen.
tail -f /var/log/hostd.log
If you just need to dump the contents of a log to your screen, use the cat command. This will then let you scroll up (Shift + PageUP) and down (Shift + PageDOWN) to find what you need.
Searching A Log
If you have a huge log or are looking for a specific event, I recommend the grep command. I often pipe (output) my tail or cat command into a grep command, which then searches the results for a string that I am looking for.
In this command below, I first tail the hostd.log to get the last few lines, and then I pipe the results into grep with a search for the word Power. The -i argument ignores case, so that it will search for any variation of the word Power.
tail /var/log/hostd.log | grep -i Power
If you’ve found that the host services could use a restart, there’s a script ready to rock that will handle this for you. (Also: Reference KB 1003490)
Managing A Host: Esxcfg-Commands
The esxcfg- commands are an assortment of tools that are VMware specific. Ranging from managing the nics, vswitches, and vmkernel ports, esxcfg- commands are the bread and butter of an ESXi Shell experience. Take note that these are slowly being phased out in favor of the new esxcli commands, but are still available and offer some features that are not yet available with esxcli.
Let’s say you had an issue where you were concerned about the MTU value on your nics. You could issue this command to quickly see what the configuration of all your nics are:
Managing a Host: Esxcli Commands
The final tools of a Ninja that I will cover involve the newest kid on the block: esxcli. Introduced with vSphere 5, this new command is an attempt to organize host management underneath a logical syntax. Instead of having to memorize a lot of root commands with esxcfg- , you now just start with esxcli and begin branching out.
So, for the MTU example above where I used esxcfg-nics -l, you could instead do:
esxcli network nic list
These are just a small handful of very simple yet powerful commands that are available to you. There are literally hundreds of commands and variations at your disposal, but I selected the ones above because I use them so often.