Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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