From d8a2f732b300cdbb892e0878fe87dbb7a0ef6d03 Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Fri, 15 Apr 2022 16:32:43 +0200 Subject: Initial commit --- lib/subcommands/ssh.bash | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 lib/subcommands/ssh.bash (limited to 'lib/subcommands/ssh.bash') diff --git a/lib/subcommands/ssh.bash b/lib/subcommands/ssh.bash new file mode 100644 index 0000000..19ead9a --- /dev/null +++ b/lib/subcommands/ssh.bash @@ -0,0 +1,39 @@ +#!/usr/bin/env bash + +subcommand() +{ + local ssh="$(config app.ssh)" + + if [[ ! -d "$BASHTARD_ETCDIR/hosts.d" ]] + then + crit "$BASHTARD_NAME/ssh" "Could not find hosts file at $BASHTARD_ETCDIR/hosts.d" + return 3 + fi + + chgdir "$BASHTARD_ETCDIR/hosts.d" + + for node in * + do + local user + local host + local ip + + user="$(config_for "$node" "ssh.user" "root")" + + # Try IPv6 first + host="$(config_for "$node" "ssh.host" "$(config_for "$node" "vpn.ipv6")")" + + if [[ -z "$host" ]] + then + # Otherwise try IPv4 + host="$(config_for "$node" "ssh.host" "$(config_for "$node" "vpn.ipv4")")" + fi + + notice "ssh" "$user@$node ($host) > $*" + + $ssh "$user@$host" "$@" + + unset user + unset host + done +} -- cgit v1.1