32 lines
835 B
Bash
Executable File
32 lines
835 B
Bash
Executable File
#!/bin/bash
|
|
CMD=$1
|
|
|
|
if ! command -v parallel-ssh &> /dev/null
|
|
then
|
|
echo "parallel-ssh could not be found. Attempting to aquire from the repo."
|
|
sudo apt install pssh
|
|
echo ""
|
|
fi
|
|
|
|
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"
|
|
echo "Please enter your sudo password."
|
|
read -s SUDOPASS
|
|
parallel-ssh -A -i -x '-tt' -t 0 -h pssh_hosts -l ansible "echo '$SUDOPASS' | $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
|