I am using CentOS 7.5.1804 with GNU bash version 4.2.46(2)-release (x86_64-redhat-linux-gnu).

For scheduled reboots within maintenance windows I calculate the minutes from now up to the next reboot. In example, for an reboot in ~3 months I would use

shutdown -r +129600

Since interested in a better understanding of bash, I am curious about what could be the highest value and how to calculate it?

An scheduled shutdown with int32 would report

shutdown -r +4294967295
Shutdown scheduled for Tue 10184-07-27 ... 

higher values are still possible, but how to calculate the possible maximum?

  • 4
    8171 years is impressive uptime. – glenn jackman Jun 12 '18 at 14:10
  • Indeed @glenn jackman, as mentioned in the question I am just curious about what could be the highest value and how to calculate it. It is to gain a better understanding about how the command and process is working and I am aware of that it is not a really rational or technically useful value. Was already looking for the source code of the command, but couldn't find it. – U880D Jun 12 '18 at 14:15

On my machine, /sbin/shutdown is a symlink to /sbin/systemctl.
Poking around in the systemctl source (https://code.launchpad.net/~ubuntu-branches/ubuntu/trusty/systemd/trusty), I see

  • the shutdown_parse_argv function parses the time spec into a variable called arg_when which is of type usec_t
  • the send_shutdownd function creates a sd_shutdown_command struct with that usec_t value
  • the sd_shutdown_command struct contains:

    /* Microseconds after the epoch 1970 UTC */
    uint64_t usec;

So, it appears the max time is:

$ \bc <<< '(2^63-1) / 10^6 / 60' # minutes
$ \bc <<< '(2^63-1) / 10^6 / 60 / 24 / 365' # years

Then again, I did not read the parse_time_spec function to see how the argument is actually parsed into a time value.

| improve this answer | |
  • Note \bc because I have a "bc" alias that I did not want to call here. – glenn jackman Jun 12 '18 at 14:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.