#!/bin/bash function rebootMachine() { local MACHINE=$1 local HOW=$2 if (( ${MACHINE} < 10 )); then MACHINE="0${MACHINE}" fi MACHINE="chrome${MACHINE}.duensing.digital" echo "Attempting reboot of ${MACHINE}..." sshpass -p password ssh -o "StrictHostKeyChecking=no" user@${MACHINE} "sudo ${HOW}" } # Install needed packages. which -s sshpass if [[ $? -eq 1 ]]; then sudo apt-get install -y sshpass fi # Figure out what to do. HOW="reboot" if [[ -z $1 ]]; then echo "$0 [all|#] {shutdown}" exit 1 fi if [[ "$2x" == "shutdownx" ]]; then HOW="poweroff" fi if [[ "$1x" == "allx" ]]; then for I in {1..13}; do rebootMachine ${I} ${HOW} done else rebootMachine ${1} ${HOW} fi