Score:2

How to enable logging of commands run through shell script in ESXi Hypervisor?

dz flag

On ESXi Hypervisor, If I run a command on the terminal via SSH, the commands are logged in the shell.log file, i.e if i run this command

[root@esxi04:~] ls -la

then I can see this command in shell.log file as:

<164>2023-02-22T09:34:24.337Z test_host shell[68783]: [root]: ls -la

But If I use a shell script instead, like this

#!/bin/sh
echo "Test"
ls -la
find / -name "*.log" -exec /bin/rm -rf {} \;

and run this script, the commands executed are not logged in shell.log file.

Is there any way I can log all these commands run through shell script as well? How to do so?

br flag
Why are you running shell scripts on the CLI?
Cool Guy avatar
dz flag
I am looking into something and, this scenario popped up. I need to confirm whether it logs or not and if not how to log them.
br flag
ESXi is not a general purpose OS and shouldn't be used like one - there are APIs to achieve most if not all of your objectives, try to use it like it's supposed to be used.
Cool Guy avatar
dz flag
Well I saw a case where an attacker gained access to the ESXi and ran a malicious shell script. So, I'm trying to find the corresponding logs related to commands executed and also want to log them if not logged by default.
br flag
Just ensure that you management interface is well protected by firewall, set strong passwords, keep the patching up to date and disable the CLI - then they can't get to it anyway.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.