From ccd930ce580dd4adb21d879c1a15e66660e3a0fe Mon Sep 17 00:00:00 2001
From: dan <me@danrh.co.uk>
Date: Tue, 19 Sep 2023 20:39:57 -0400
Subject: feat: add run-command-on-many-different-vps.sh

---
 run-command-on-many-different-vps.sh | 42 ++++++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
 create mode 100644 run-command-on-many-different-vps.sh

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"
-- 
cgit v1.2.3