VMware Cloud Community
gboskin
Enthusiast
Enthusiast
Jump to solution

Script to pull log files from ESX hosts

we have a situation where we need to pull up some log files from each ESX hosts in a cluster to send off ...

log files like esx.conf, and /proc/scsi/ql/ all zipped.. for each individual hosts

is there a way this can be done through the ttookit??

1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

There are currently, afaik, no cmdlets in the VITK that allow you to access the local file system of the ESX COS.

But with the plink.exe command and sudo you can get something that comes close.

$User = <ESX-account>
$Pswd = <ESX-account-password>
$Computer = <ESX-hostname>
$plink = "<path to >\plink.exe"
$plinkoptions = " -v -batch -pw $Pswd"
$cmd1 = 'sudo -u root cat /etc/vmware/esx.conf'

$remoteCommand = '"' + $cmd1 + '"'
$command = $plink + " " + $plinkoptions + " " + $User + "@" + $computer + " " + $remoteCommand

$msg = Invoke-Expression -command $command 
$msg | Set-Content "C:\Temp\esx.conf"

In this script the esx.conf file is displayed and the output is captured and stored in a file on the local file system.

For the setup of sudo see my notes in


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

6 Replies
LucD
Leadership
Leadership
Jump to solution

There are currently, afaik, no cmdlets in the VITK that allow you to access the local file system of the ESX COS.

But with the plink.exe command and sudo you can get something that comes close.

$User = <ESX-account>
$Pswd = <ESX-account-password>
$Computer = <ESX-hostname>
$plink = "<path to >\plink.exe"
$plinkoptions = " -v -batch -pw $Pswd"
$cmd1 = 'sudo -u root cat /etc/vmware/esx.conf'

$remoteCommand = '"' + $cmd1 + '"'
$command = $plink + " " + $plinkoptions + " " + $User + "@" + $computer + " " + $remoteCommand

$msg = Invoke-Expression -command $command 
$msg | Set-Content "C:\Temp\esx.conf"

In this script the esx.conf file is displayed and the output is captured and stored in a file on the local file system.

For the setup of sudo see my notes in


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

gboskin
Enthusiast
Enthusiast
Jump to solution

So am I ok in doing this

1) place plink.exe on my local drive

2) ensure sudo is installed on all hosts

run this script form VI toolkit

********************************************************************************************************

$vcserver = "";

*

Connect-VIServer $vcserver

*

$User = &lt;ESX-account&gt;

$Pswd = &lt;ESX-account-password&gt;

$plink = "&lt;path to &gt;\plink.exe"

$plinkoptions = " -v -batch -pw $Pswd"

ForEach ($VMHosts in Get-VMHost | Sort Name)

{

$cmd1 = 'sudo -u root cat /etc/vmware/esx.conf'

$remoteCommand = '"' + $cmd1 + '"'

$command = $plink + " " + $plinkoptions + " " + $User + "@" + $VMHosts + " " + $remoteCommand

$msg = Invoke-Expression -command $command

$msg | Set-Content "C:\Temp\$VMHosts"

}

*

disconnect-viserver -confirm:$false

*

P/S output files needs to be zipped

0 Kudos
LucD
Leadership
Leadership
Jump to solution

Yes, that should do the trick (in my opinion).


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
johnwilk
Contributor
Contributor
Jump to solution

If you do not want to use the command line to collect this information

you can use the VI Client. You can connect to either a single ESX or

ESXi host, or you can generate diagnostic bundles for multiple hosts by

connecting to a vCenter Server. Once you connect, select File from the

top menu, Export, and finally the Export Diagnostic Data option.

0 Kudos
LucD
Leadership
Leadership
Jump to solution

True, but isn't that a bit of overkill to get a few files from your ESX server ?

And the /proc/scsi folder is not in the bundle.

Btw you can create the diagnostic bundle as well from with PS

$esxName = <ESX-hostname>
Connect-ViServer $esxName
Get-Log -Bundle -DestinationPath "C:\Bundles"


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
gboskin
Enthusiast
Enthusiast
Jump to solution

The script works fine but howerever the command

$command = $plink + " " + $plinkoptions + " " + $User + "@" + $VMHosts + " " + $remoteCommand

echo alot of information to screen . At frist thought they were errors but realised it was just information....(can this be surpressed)

Also i had to have logged onto each host at least once before ( ssh authentication) before running the script