Skip to content

Commit

Permalink
Tidy up error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ThetaSinner committed Jun 19, 2024
1 parent 03b2736 commit 17ec976
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions scripts/exec_on_targets.ab
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { input, lines } from "std"
import { input, lines, exit } from "std"

let cmd = input("Enter the command to run: ")

let x = $cat "./targets.yaml" | grep "ws://"$ failed {
echo "[{status}] Failed to read file"
exit(1)
}

let attempted = 0
Expand All @@ -12,14 +13,14 @@ let succeeded = 0
loop index, line in lines(x) {
let ip = $echo {line} | cut -b 8- | rev | cut -b 6- | rev$ failed {
echo "[{status}] failed to extract ip from {line}"
continue
}
echo "Running on target {index} at {ip}"
attempted = attempted + 1
let result = $ssh "-oPreferredAuthentications publickey" "root@{ip}" {cmd}$ failed {
succeeded = succeeded - 1
echo "[{status}] failed to run command on {ip}"
continue
}

succeeded = succeeded + 1
echo result
}
Expand Down

0 comments on commit 17ec976

Please sign in to comment.