Allow host wildcard
cacharle opened this issue · 9 comments
It would be nice if pssh
could read my ssh config and allow me to pick hosts based on a wildcard.
e.g
$ cat ~/.ssh/config
Host hello-foo
...
Host hello-bar
...
and we run: $ pssh -H 'hello-*' echo bye
to execute the command on hello-foo
and hello-bar
I am willing to contribute this feature if it's not available yet.
What if the string after Host
already contains a wildcard?
I guess we just ignore Host
containing wild cards?
That means when the user optimizes their ssh config, they may silently break existing pssh commands / scripts. It doesn't sound great.
Also, you can just grep out your hosts. Perhaps a way to generate a host list dynamically is better?
Indeed, you can do create a simple script to grep the hosts.
I just think that it's something that is convenient and I don't think every person that uses this project should have to make their own script for this.
If you're scared of breaking existing scripts, we can just create a new option like --host-regex
.
I mean the Host
line is not a host list, but host patterns. Giving one thing two roles isn't a good idea.
Btw, I wonder why does one have a lot of non-wildcard Host
lines, but still want to run the same command on them?
Lots of device with a static IP and not human friendly domain names.
/etc/hosts
seems to be a better place? Except that it needs root.
ye, but then if I want to run something on 10 devices, I need to list them one by one, which is painful:
pssh -H "location-1-device-1 location-1-device-2 location-1-device-3 location-1-device-4 location-1-device-5 location-1-device-6 location-1-device-7 location-1-device-8 location-1-device-9" echo smth
I'd like to be able to do: pssh -H 'location-1-device-*' echo smth
or pssh -H 'location-*-device-*'
I guess I'll write a script for that..
For posterity, here is what I came up with:
#!/bin/sh
set -e
host_regex="$1"
shift
host_tmp_file=$(mktemp)
echo 'Running on hosts:'
grep '^Host ' ~/.ssh/config |
grep -v '\*' |
cut -d ' ' -f 2 |
grep -E "$host_regex" |
tee "$host_tmp_file"
echo '----------------'
pssh -h "$host_tmp_file" "$@"
Usage: ./pssh-regex 'location-.*-device-.*' -i -p 10 echo hello