Created
December 6, 2019 01:16
-
-
Save fabiojaniolima/1c645e6b9c01ead7866945928e58af59 to your computer and use it in GitHub Desktop.
Execute script ou comandos remotos em múltiplos servidores. Necessário chave de autenticação.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
SERVERS=(host01 host02 host03); | |
echo "##################"; | |
echo "# Header Example #"; | |
echo -e "##################\n"; | |
echo -e "Run on: $(date '+%F - %T')\n" | |
for i in "${!SERVERS[@]}" | |
do | |
OUTPUT=$(ssh -q -oStrictHostKeyChecking=no username@${SERVERS[i]} "./my-script.sh" 2> /dev/null) | |
STATUS=$? | |
if [[ $STATUS -eq 0 ]]; | |
then | |
echo -e "${SERVERS[i]}:\n$OUTPUT\n"; | |
elif [[ $STATUS -eq 127 ]]; | |
then | |
echo -e "${SERVERS[i]}: ERROR => SCRIPT \"my-script.sh\" NOT FOUND!\n"; | |
else | |
echo -e "${SERVERS[i]}: UNDETERMINED SSH ERROR!\n"; | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment