Update rebootSchedule.sh

This commit is contained in:
2023-11-21 15:13:48 +01:00
parent 2d7641b1dd
commit abad7d298f

View File

@@ -1,81 +1,70 @@
#!/bin/bash #!/bin/bash
# Zie ook https://wiki.de-roo.org/doku.php/cron # Zie ook https://wiki.de-roo.org/doku.php/cron
FIRST=("fs01") FIRST=("fs01")
SECOND=("web06" "web03" "net04") SECOND=("web06" "web03" "net04")
THIRD=("net02" "net03" "net05" ) THIRD=("net02" "net03" "net05" )
REST=("dt03" "git01" "run01" "has01" "iam01" "man01" "mdm01" "minecraft" "nms01" "pbx01" "rpi03" "web04" "web05" "web07" "mail02" "cloud01" "srv01" "siem01" "web08" "web09" "dms01") REST=("dt03" "git01" "run01" "has01" "iam01" "man01" "mdm01" "minecraft" "nms01" "pbx01" "rpi03" "web04" "web05" "web07" "mail02" "cloud01" "srv01" "siem01" "web08" "web09" "dms01")
timeToWait=900
############################################
# 1:00h (uit crontab) FIRST # ############################################
############################################ # 1:00h (uit crontab) FIRST #
for SERVER in "${FIRST[@]}"; do ############################################
echo "------------------------------------" for SERVER in "${FIRST[@]}"; do
date +"%H:%M:%S %d-%m-%Y" echo "------------------------------------"
echo "Starting reboot of $SERVER" date +"%H:%M:%S %d-%m-%Y"
ssh "$SERVER" reboot now echo "Starting reboot of $SERVER"
sleep 60 ssh "$SERVER" reboot now
done sleep 60
done
############################################
# 1:15h SECOND # ############################################
############################################ # 1:15h SECOND #
timeNow=$(date +%s) ############################################
targetTime=$(date -d 01:15 +%s) echo "Waiting $timeToWait seconds"
timeToWait=($targetTime - $timeNow) sleep "$timeToWait"
echo "Waiting $timeToWait seconds"
sleep "$timeToWait" for SERVER in "${SECOND[@]}"; do
echo "------------------------------------"
for SERVER in "${SECOND[@]}"; do date +"%H:%M:%S %d-%m-%Y"
echo "------------------------------------" echo "Starting reboot of $SERVER"
date +"%H:%M:%S %d-%m-%Y" ssh "$SERVER" reboot now
echo "Starting reboot of $SERVER" sleep 60
ssh "$SERVER" reboot now done
sleep 60
done ############################################
# 1:30h THIRD #
############################################ ############################################
# 1:30h THIRD # echo "Waiting $timeToWait seconds"
############################################ sleep $timeToWait
timeNow=$(date +%s)
targetTime=$(date -d 01:30 +%s) for SERVER in "${THIRD[@]}"; do
timeToWait=($targetTime - $timeNow) echo "------------------------------------"
echo "Waiting $timeToWait seconds" date +"%H:%M:%S %d-%m-%Y"
sleep $timeToWait echo "Starting reboot of $SERVER"
ssh "$SERVER" reboot now
for SERVER in "${THIRD[@]}"; do done
echo "------------------------------------"
date +"%H:%M:%S %d-%m-%Y" ############################################
echo "Starting reboot of $SERVER" # 1:45h REST #
ssh "$SERVER" reboot now ############################################
done echo "Waiting $timeToWait seconds"
sleep $timeToWait
############################################
# 1:45h REST # for SERVER in "${REST[@]}"; do
############################################ echo "------------------------------------"
timeNow=$(date +%s) date +"%H:%M:%S %d-%m-%Y"
targetTime=$(date -d 01:45 +%s) echo "Starting reboot of $SERVER"
timeToWait=($targetTime - $timeNow) ssh "$SERVER" reboot now
echo "Waiting $timeToWait seconds" done
sleep $timeToWait
############################################
for SERVER in "${REST[@]}"; do # 1:55h CUSTOM #
echo "------------------------------------" ############################################
date +"%H:%M:%S %d-%m-%Y" echo "Waiting $timeToWait seconds"
echo "Starting reboot of $SERVER" sleep $timeToWait
ssh "$SERVER" reboot now echo "------------------------------------"
done date +"%H:%M:%S %d-%m-%Y"
echo "Starting reboot of $(hostname)"
############################################ shutdown -r 5 "Reboot in 5 minutes."
# 1:55h CUSTOM #
############################################
timeNow=$(date +%s)
targetTime=$(date -d 01:55 +%s)
timeToWait=($targetTime - $timeNow)
echo "Waiting $timeToWait seconds"
sleep $timeToWait
echo "------------------------------------"
date +"%H:%M:%S %d-%m-%Y"
echo "Starting reboot of $(hostname)"
shutdown -r 5 "Reboot in 5 minutes."