HI,
kindly suggest me a command in which it could check the vm uptime through putty in vmware 6.0
Thanks,
shankar.p
Why would you need Putty?
You can do this via PowerCLI, something like this
$stat = 'sys.osuptime.latest'
$entity = Get-VM
Get-Stat -Entity $entity -Stat $stat -Realtime -MaxSamples 1 -ErrorAction SilentlyContinue |
Select @{N='VM';E={$_.Entity.Name}},
@{N='Uptime (d.hh:mm:ss)';E={[timespan]::FromSeconds($_.value)}}
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks for your update,
we already running some script in putty we thought to add up-time in the same script
I'm making the assumption that you're using putty to script Linux.
You can use the uptime command:
~ # uptime
09:52am up 9 days 13:04, 1 user, load average: 0.89, 0.73, 0.56
If you just want the days and hours, use this:
~# uptime | sed 's/.*up \([^,]*\), .*/\1/'
9 days 13:05
If putting in a bash script you can set the output to a variable to use later:
uptime="$(uptime | sed 's/.*up \([^,]*\), .*/\1/')"
echo $uptime
Then I guess your thread shouldn't be in the PowerCLI Community.
Shall I move it?
Blog: lucd.info Twitter: @LucD22 Co-author PowerCLI Reference
Thanks,
but it shows only host update time I need vm uptime
OK, so you're using putty to connect to the ESXi host and then you want to run a command line option from the ESXi host shell to enumerate a specific VM's uptime?
You'll have to do some tinkering to script it further, but you could get it with this
[root@hwlesxi07:/bin] vim-cmd vmsvc/getallvms | grep hwlvra7201
320 hwlvra7201 [NFS-01] hwlvra7201/hwlvra7201.vmx sles11_64Guest vmx-07 VMware vRealize Automation enables customized, self-service provisioning and lifecycle management of cloud services that comply with established business policies.
[root@hwlesxi07:/bin] vim-cmd vmsvc/get.runtime 320 | grep bootTime
bootTime = "2017-11-17T19:51:37.503343Z",
You would have to parse the vmID from the first command ("320" in the example) and use it in the second command. Parse the boot time value and subtract it from todays date to get total uptime.
I don't know of any way to get a scalar value for uptime (i.e. seconds, days, etc.) of a VM from the host command line unless I missed a value somewhere in the vim-cmd vmsvc/ namespace. You can play with the commands in there to see what might be of value to you.