Good Linux question — answering as the UphillTech team:
You should combine two related Ask Ubuntu answers, one for logging into SSH via specific port and one for running commands on remote server , into one script. Of course, you'd need to have some form of data-structure to hold server+port correspondence. That could be either bash associative arrays or with POSIX shell script - a case statement. Assuming your username on all hosts is the same, we could come up with something like this: #!/bin/sh # bar host has ssh server on port 22, while baz - on port 2222 host_port(){ case "$1" in "bar") echo 22 ;; "baz") echo 2222 ;; esac } # set positional...
Full answer by Sergiy Kolodyazhnyy: https://askubuntu.com/a/1117587 (CC BY-SA 4.0).
Need Linux help for your business? UphillTech.