Skip to content

Instantly share code, notes, and snippets.

@lucasaba
Created December 10, 2016 14:57
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 lucasaba/bfc762f49d945f090694dfa5f2c36787 to your computer and use it in GitHub Desktop.
Save lucasaba/bfc762f49d945f090694dfa5f2c36787 to your computer and use it in GitHub Desktop.
Gestisce l'aggiornamento dei server tramite ssh e apt
#!/bin/bash
show_help() {
cat << EOF
Usage: ${0##*/} [-hal] [SERVER]...
Invoca l'apt-get su uno o più server remoti.
-h mostra questa help ed esce
-a modifica il comando di apt-get in autoremove
-l effettua l'upgrade dei server virtuali interni
EOF
}
APT_COMMAND='upgrade'
GREEN_COLOR='\033[0;32m'
NO_COLOR='\033[0m'
SERVERS=$@
OPTIND=1
while getopts "hla" opt; do
case "$opt" in
h) show_help
exit 0
;;
a) APT_COMMAND='autoremove'
;;
l) SERVERS=("192.168.1.23" "192.168.1.24" "192.168.1.25" "192.168.1.27")
;;
esac
done
for server in ${SERVERS[@]}
do
if [ $server == '-a' ]; then
continue
elif [ $server == '-l' ]; then
continue
fi
NAME=$server
if [[ $server =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then
NAME=`host $server | cut -d " " -f5`
fi
printf "${GREEN_COLOR}Esecuzione del comando su $NAME ${NO_COLOR}"
echo
ssh $server -t "sudo apt-get $APT_COMMAND -y"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment