1

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
boardrider
  • 949
  • 2
  • 18
  • 29

1 Answers1

2

In the shutdown source, an int is used for the waiting time, so on a typical machine the upper limit is 2147483647 minutes, that is 4083 years from now.

Here are the relevant parts from the source:

int main(int argc, char **argv)
{
        ...
        int                     c, i, wt;
        ...
        if (strchr(when, ':') == NULL) {
                /* Time in minutes. */
                wt = atoi(when);
                if (wt == 0 && when[0] != '0') usage();
        } else {
                ...
        }
        ...
        /* Give warnings on regular intervals and finally shutdown. */
        if (wt < 15 && !needwarning(wt)) warn(wt);
        while(wt) {
                if (wt <= 5 && !didnolog) {
                        donologin(wt);
                        didnolog++;
                }
                if (needwarning(wt)) warn(wt);
                hardsleep(60);
                wt--;
        }
        shutdown(halttype);

        return 0; /* Never happens */
}