Skip to content

Instantly share code, notes, and snippets.

@caius
Created September 25, 2012 13:54
Show Gist options
  • Save caius/3782063 to your computer and use it in GitHub Desktop.
Save caius/3782063 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# types=$(brightbox-types -s list | awk '{ print "types[\"" $(NF-3) "\"] = " $(NF-2) }')
# prices from http://brightbox.com/pricing/ - as of 2012-09-25
# Assumes 720 hours (30 days) in a month
# Handles calculating with a discount, if that applies
brightbox-servers -s list 2> /dev/null | awk '
BEGIN {
# If you have a discount, set it here. Express in inverse decimal %age (0.9 == 10% off, 0.2 == 20% off, etc)
discount=0.0
# 20% VAT
vat=1.2
split("nano,mini,small,medium,large,xl,xxl", names, ",")
types["nano"] = 512
types["mini"] = 1024
types["small"] = 2048
types["medium"] = 4096
types["large"] = 8192
types["xl"] = 16384
types["xxl"] = 32768
prices["nano"] = 0.025
prices["mini"] = 0.05
prices["small"] = 0.10
prices["medium"] = 0.20
prices["large"] = 0.40
prices["xl"] = 0.80
prices["xxl"] = 1.60
}
{
machines[$3] += 1
total_hourly_cost += prices[$3]
}
END {
print " Monthly cost: " total_hourly_cost * 720 " GBP"
print " w/ VAT: " (total_hourly_cost * 720) * vat " GBP"
if (discount > 0.0) {
print " w/ discount: " (total_hourly_cost * 720) * discount " GBP"
print " w/ discount & VAT: " ((total_hourly_cost * 720) * discount) * vat " GBP"
}
for (key in types)
print key ": " machines[key]
}
'
julius:~ caius$ ./bb-usage
Monthly cost: 90 GBP
w/ VAT: 108 GBP
small:
medium:
xl:
mini: 2
large:
xxl:
nano: 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment