I need to shut down all machine in a site - on a Sunday.
I created a script (at bottom) that will execute the following on each machine, on the preceding Friday:
command="hostname ; sudo shutdown -h 2250"
ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=1 -t privuser@${host} $command
Is 2250 a valid time interval to the shutdown command?
Notes:
- Machines run CentOS/RedHat 7.
- I Googled, but could not find any upper bound mentioned to the time parameter of the shutdown command.
This is the full script:
#!/usr/bin/env bash
# WHEN: Sunday, October 28, 2018 from 8:00 a.m.
# to calculate minutes: ( (24 - now_hour)*60 + 1440 + 300 )
# if run on 15:30 Friday: (24 - 15.5) * 60 + 1440 + 300 = 2250
ignored=(168 12 15 38 42 46 99 180)
command="hostname ; sudo shutdown -h 2250"
for tuple in {10..204} ;
do
host="192.168.1.${tuple}"
if [[ $(printf "_[%s]_" "${ignored[@]}") =~ .*_\[$tuple\]_.* ]]; then
echo ">>> will skip $host"
continue
fi
echo ">>> try '$command' on $host"
ping -c1 $host
ssh -o StrictHostKeyChecking=no -o ServerAliveInterval=1 -t privuser@${host} $command
done