summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--run-command-on-many-different-vps.sh42
1 files changed, 42 insertions, 0 deletions
diff --git a/run-command-on-many-different-vps.sh b/run-command-on-many-different-vps.sh
new file mode 100644
index 0000000..024bc87
--- /dev/null
+++ b/run-command-on-many-different-vps.sh
@@ -0,0 +1,42 @@
+
+vm_create () {
+ doctl compute droplet create "$1" \
+ --image ubuntu-22-04-x64 \
+ --size s-1vcpu-512mb-10gb \
+ --ssh-keys 28174738 --ssh-keys 28964182 --ssh-keys 28963526 \
+ --region nyc1 \
+ --wait
+}
+
+vm_get_ip () {
+ IP=null
+ while [[ $IP == null ]]; do
+ NETWORKS=`doctl compute droplet get "$1" -o json | jq --args '.[0].networks.v4'`
+ if [[ $NETWORKS != null ]]; then
+ IP=`echo $NETWORKS | jq -r --args '.[] | select(.type!="private") | .ip_address'`
+ else
+ sleep 1
+ fi
+ done
+}
+
+vm_destroy () {
+ doctl compute droplet delete "$1" -f
+}
+
+
+dropletId=$(openssl rand -hex 8)
+
+vm_create "$dropletId"
+vm_get_ip "$dropletId"
+
+results=$(ssh -o StrictHostKeyChecking=no "root@$IP" '
+ curl -s "https://shared.danrh.co.uk/example.json"
+ curl -s "https://shared.danrh.co.uk/example.json"
+ curl -s "https://shared.danrh.co.uk/example.json"
+ curl -s "https://shared.danrh.co.uk/example.json"
+')
+
+vm_destroy "$dropletId"
+
+echo "$results"