Skip to content

Instantly share code, notes, and snippets.

@n-johnson
Created March 25, 2016 04:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n-johnson/d980c31c413eed39280b to your computer and use it in GitHub Desktop.
Save n-johnson/d980c31c413eed39280b to your computer and use it in GitHub Desktop.
ec2-host cached
#!/bin/bash
MAX_CACHE=21600 # 6 hours (sec)
EC2_CACHE="$HOME/.ec2_host"
file_age() {
stat -f "%Sm" -t "%s" "$1"
}
cur_time=$(date "+%s")
last_mod=$(file_age "$EC2_CACHE")
cache_age=$(echo "$cur_time - $last_mod" | bc)
if [ "$cache_age" -gt "$MAX_CACHE" ]; then
ec2-host > "$EC2_CACHE"
fi
cat "$EC2_CACHE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment