Skip to content

Instantly share code, notes, and snippets.

@somic
Created June 4, 2009 22:16
Show Gist options
  • Select an option

  • Save somic/123889 to your computer and use it in GitHub Desktop.

Select an option

Save somic/123889 to your computer and use it in GitHub Desktop.

Revisions

  1. somic created this gist Jun 4, 2009.
    20 changes: 20 additions & 0 deletions gistfile1.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    #!/bin/bash
    #
    # Prints out how many seconds ago this EC2 instance was started
    #
    # It uses Last-Modified header returned by EC2 metadata web service, which as far
    # as I know is not documented, and hence I assume there is no guarantee
    # that Last-Modified will be always set correctly.
    #
    # Use at your own risk.
    #

    t=/tmp/ec2.running.seconds.$$

    if wget -q -O $t http://169.254.169.254/latest/meta-data/local-ipv4 ; then
    echo $(( `date +%s` - `date -r $t +%s` ))
    rm -f $t
    exit 0
    fi

    exit 1