Skip to content

Instantly share code, notes, and snippets.

@keymon
Created July 2, 2019 17:14
Show Gist options
  • Select an option

  • Save keymon/f0f8cf8ed386d69fa0d41b11eb42a3be to your computer and use it in GitHub Desktop.

Select an option

Save keymon/f0f8cf8ed386d69fa0d41b11eb42a3be to your computer and use it in GitHub Desktop.
Check date of AWS token in bash
get_token_ttl() {
if [ -n "${AWS_CREDENTIAL_EXPIRE}" ]; then
if date --version 2>&1 | grep -q GNU; then
token_epoch="$(date -d "${AWS_CREDENTIAL_EXPIRE}" +%s)"
elif date --version 2>&1 | grep -q ymwdHMS; then
token_epoch="$(date -j -u -f '%Y-%m-%dT%H:%M:%SZ' "${AWS_CREDENTIAL_EXPIRE}" +%s)"
fi
current_epoch="$(date +%s)"
echo "$(( token_epoch - current_epoch ))"
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment