Add Multish script

This commit is contained in:
Thomas Cole 2021-10-06 15:50:03 -04:00
parent 75a31b6912
commit b41e73fb35
2 changed files with 30 additions and 0 deletions

22
multissh/multish.sh Executable file
View File

@ -0,0 +1,22 @@
#!/bin/bash
CMD=$1
echo -e "You are about to run \e[1;32m$CMD\e[0m on all hosts."
run () {
if grep -q "sudo" <<< "$CMD"; then
echo "sudo command detected. Attempting to elevate permissions"
parallel-ssh -A -i -x '-tt' -t 0 -h pssh_hosts -l ansible "echo 'ansible' | $CMD && history -c"
else
parallel-ssh -A -i -x '-tt' -h pssh_hosts -l ansible "$CMD && history -c"
fi
}
while true; do
read -p "Are you sure? (y/n): " yn
case $yn in
[Yy]* ) run; break;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done

8
multissh/pssh_hosts Normal file
View File

@ -0,0 +1,8 @@
w150-debian.local
center6-debian.local
library-debian.local
lacky-debian.local
foruma-debian.local
forumb-debian.local
forumc-debian.local
musicroom-debian.local