PowerCLI

 View Only
  • 1.  Deleting historical vmware-*.log files

    Posted Feb 27, 2013 04:01 PM

    I would like to run a script at the top level of a given datastore (with multiple VM folders in it) that will go through each VM directory and delete all historical vmware-**.log files that may exist (leaving only the currently used vmware.log file in place.) I have tried several posted methods, but none seemed to work. Can someone point me in the right direction and/or provide me the right command to run?  (Running ESXi 5.1 patched to current)



  • 2.  RE: Deleting historical vmware-*.log files

    Posted Feb 27, 2013 04:05 PM

    Note: Discussion successfully moved from VMware ESXi 5 to Automation Tools



  • 3.  RE: Deleting historical vmware-*.log files
    Best Answer

    Posted Feb 27, 2013 06:00 PM

    If you use PowerCLI you could do something like this:

    Get-DataStore ESX02_LOCAL2 | New-DataStoreDrive -Name DS
    cd DS:
    Get-ChildItem -Recurse | where {$_.Name -like "vmware-*.log"}
    Remove-PSDrive -Name DS

    If you're happy with the files that are found you would just change the one line to this to delete the files:

    Get-ChildItem -Recurse | where {$_.Name -like "vmware-*.log"} | foreach ($_) {remove-item $_.fullname}

    If you're connected to a console or SSH session and just need a one time run you could run this to list the files

    find /vmfs/volumes/ -name vmware-*.log  -exec ls  {} \;

    and this to delete the files

    find /vmfs/volumes/ -name vmware-*.log  -exec ls  {} \; | xargs rm



  • 4.  RE: Deleting historical vmware-*.log files

    Posted Feb 27, 2013 07:14 PM

    Score!  This is what i was looking for.  The only problem with the remove statement is that it is not handling folder names with spaces in there.  For instance...if the VM folder name is V000SQL0100, it works fine.  If it was named something like "Windows 2008 Base Image"....it does not.  How can the rm command be modified to work with these?



  • 5.  RE: Deleting historical vmware-*.log files

    Broadcom Employee
    Posted Feb 27, 2013 06:16 PM

    Instead of manually deleting the logs, you can control the number of logs as well as the size by adding in the following VM Advanced Settings to the VM:

    limit-log-number

    limit-log-size

    For more details, please refer to the vSphere Security Hardening Guide http://blogs.vmware.com/security/2013/02/vsphere-5-1-hardening-guide-draft-now-available.html