-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpricing_check.sh
51 lines (40 loc) · 1.43 KB
/
pricing_check.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
while getopts s:p:l:r: option
do
case "${option}"
in
s) skuName=${OPTARG};;
p) productName=${OPTARG};;
l) location=${OPTARG};;
r) isLoop=${OPTARG};;
esac
done
if [ "$skuName" == "" ] ; then
skuName='DS3 v2'
fi
if [ "$location" == "" ] ; then
location='US East'
fi
if [ "$productName" == "" ] ; then
productName='Virtual Machines DSv2 Series'
fi
if [ "$isLoop" == "" ] ; then
isLoop=false
fi
echo "Checkin prices for '$skuName' VM's in '$location' location"
while true
do
vmPrice=$(az rest --method GET --url "https://prices.azure.com/api/retail/prices?\$filter=skuName eq '$skuName' AND location eq '$location' AND serviceName eq 'Virtual Machines' AND reservationTerm eq null AND productName eq '$productName'" --query 'Items [0].unitPrice' --only-show-errors)
spotVmPrice=$(az rest --method GET --url "https://prices.azure.com/api/retail/prices?\$filter=contains(skuName,'$skuName Spot') AND location eq '$location' AND serviceName eq 'Virtual Machines' AND productName eq '$productName'" --query 'Items [0].unitPrice' --only-show-errors)
echo "Regular VM price is: $vmPrice"
echo "Spot VM price is: $spotVmPrice"
if [ "$isLoop" == false ] ; then
break
fi
if read -n1 -r -p "Do you want to check prices every 60 seconds? [y]es|[n]o" && [[ $REPLY == 'n' ]]; then
break
fi
echo
echo 'Press Ctrl+C when you no longer need price to be calculated'
sleep 60
done