I searched endless hours for this but I was unable to find anything that could help me.
I'm writing a script to calculate the launch-time of a particular instance in EC2 and to return the total running time in seconds. When I run this incomplete script I get the value of 'gettimeoutput' as something like '2015-01-28T01:56:11.000Z' (see reference). I just want this in a proper format so that I can use dateDiff() function to calculate time elapsed till the current moment.
'getltimef' would be the starting time in dateDiff readable format and 'timeinsec' would be the final output (time elapsed). Starttimer() function would start a silent timer that will also keep updating the value of 'timeinsec' variable.
Could someone help me with this, please?
References:
1] PHP Parsing Amazon EC2 instance 'launchTime'
2] http://giantdorks.org/alain/how-to-test-age-of-an-aws-instance-in-a-shell-script-2
Function getinfo()
Set instanceid = CreateObject("MSXML2.XMLHTTP.3.0")
Set regiondata = CreateObject("MSXML2.XMLHTTP.3.0")
instanceid.Open "GET", "http://169.254.169.254/latest/meta-data/instance-id", False
instanceid.Send
regiondata.Open "GET", "http://169.254.169.254/latest/meta-data/placement/availability-zone", False
regiondata.Send
Const getltimeFinished = 1
Const getltimeFailed = 2
getltimeCommand = "aws ec2 --region " regiondata.responseText " describe-instances " instanceid.responseText "--filter=""launch-time"""
Set getltimeShell = CreateObject("WScript.Shell")
Set getltimeShellExec = getltimeShell.Exec(getltimeCommand)
Select Case getltimeShellExec.Status
Case getltimeFinished
launchtimedetermined = true
getltimeOutput = getltimeShellExec.StdOut.ReadAll
Case getltimeFailed
launchtimedetermined = false
End Select
if (launchtimedetermined) = false Then
timeinsec = 240
Else
'getltimef script'
'getltimef = maybe regexp can work here?'
'timeinsec = datediff("s", getltimef, now())'
Call starttimer()
End Function
Thank you!