# License Type: GNU GENERAL PUBLIC LICENSE, Version 3
#
# Add Features:
#multi-region, all-region
#handle as-ag with min, mix and "desired cost"
#randomize ec2-list temp file, keep from clobbering
#####
#ec2-cost-calculate start
#confirms that executables required for succesful script execution are available
prerequisitecheck()
{
for prerequisite in basename awk ec2-describe-instances
do
#use of "hash" chosen as it is a shell builtin and will add programs to hash table, possibly speeding execution. Use of type also considered - open to suggestions.
hash$prerequisite&> /dev/null
if[[$?==1]]#has exits with exit status of 70, executable was not found
thenecho"In order to use `basename $0`, the executable \"$prerequisite\" must be installed." 1>&2;exit70
fi
done
}
#calls prerequisitecheck function to ensure that all executables required for script execution are available
prerequisitecheck
#handles options processing
whilegetopts :r:p:o: opt
do
case$opt in
p)period="$OPTARG";;
r)region="$OPTARG";;
o)output="$OPTARG";;#as of 2011-11-27 not implemented
*)echo"Error with Options Input. Cause of failure is most likely that an unsupported parameter was passed or a parameter was passed without a corresponding option." 1>&2;exit 64;;
esac
done
# period validator and cost multiplier
case$period in
"")multiple=1;period=hour ;;
hour|Hour)multiple=1;;;
day|Day)multiple=24;;
week|Week)multiple=168;;
month|Month)multiple=720;;
year|Year)multiple=8760;;
*)echo"The \"$period\" period does not exist. You must specify a valid period for which to calculate AWS cost (example: -p hour or -p day)." 1>&2;exit 64;;
*)echo"The \"$region\" region does not exist. You must specify a valid region for which to calculate AWS cost (example: -r us-east-1 or -r us-west-1)." 1>&2;exit 64;;
esac
#ensures that headers are only printed on the first run