Skip to content

Instantly share code, notes, and snippets.

@fabiojaniolima
Created December 6, 2019 01:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fabiojaniolima/1c645e6b9c01ead7866945928e58af59 to your computer and use it in GitHub Desktop.
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.
#!/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