diff --git a/reboot-all-chromes.sh b/reboot-all-chromes.sh index c77d9c4..64b8755 100755 --- a/reboot-all-chromes.sh +++ b/reboot-all-chromes.sh @@ -2,26 +2,40 @@ function rebootMachine() { - local machine=$1 - if (( ${machine} < 10 )); then - machine="0${machine}" + 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 reboot" + 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 - for i in {1..13}; do - rebootMachine $i + 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 + rebootMachine ${1} ${HOW} fi