Automation

 View Only
  • 1.  Script to pull log files from ESX hosts

    Posted Mar 13, 2009 11:01 AM

    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??



  • 2.  RE: Script to pull log files from ESX hosts
    Best Answer

    Posted Mar 13, 2009 12:00 PM

    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



  • 3.  RE: Script to pull log files from ESX hosts

    Posted Mar 13, 2009 12:31 PM

    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



  • 4.  RE: Script to pull log files from ESX hosts

    Posted Mar 13, 2009 02:23 PM

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



  • 5.  RE: Script to pull log files from ESX hosts

    Posted Mar 13, 2009 02:29 PM

    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.



  • 6.  RE: Script to pull log files from ESX hosts

    Posted Mar 13, 2009 02:40 PM

    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"
    



  • 7.  RE: Script to pull log files from ESX hosts

    Posted Mar 13, 2009 03:08 PM

    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