5

Is it possible to change the default message broadcasted by shutdown to something else?

talles
  • 155
  • 1
  • 5

2 Answers2

6

As @Zelda mentioned the messages are hardcoded. If you want to change it beyond amending the message with additional bits:

$ sudo shutdown -h +120 Save your work.

You'll need to recompile shutdown, creating your own executable that includes the customized message.

For example, here's a sample source file, shutdown.c. Lines such as these would need to be changed, and the .c files would need to be rebuilt.

/*
 *      Tell everyone the system is going down in 'mins' minutes.
 */
void warn(int mins)
{
        char buf[MESSAGELEN + sizeof(newstate)];
        int len;

        buf[0] = 0;
        strncat(buf, message, sizeof(buf) - 1);
        len = strlen(buf);

        if (mins == 0)
                snprintf(buf + len, sizeof(buf) - len,
                        "\rThe system is going down %s NOW!\r\n",
                        newstate);
        else
                snprintf(buf + len, sizeof(buf) - len,
                        "\rThe system is going DOWN %s in %d minute%s!\r\n",
                                newstate, mins, mins == 1 ? "" : "s");
        wall(buf, 0);
}
slm
  • 363,520
  • 117
  • 767
  • 871
  • I'm kinda surprised that it's hardcoded. I wonder if they just didn't thought about it or if it was a conscious decision with security in mind, preventing someone to do a shutdown with pointless message or no message at all. – talles Nov 27 '13 at 16:33
  • @talles - probably a little bit of both. You don't want people playing games with the messages. – slm Nov 27 '13 at 19:46
4

You cannot change the default message, you can only add some specific message of your by providing this after the time:

# shutdown 60 Down in an hour

Broadcast message from zelda@mongrel2_test
     (/dev/pts/0) at 6:37 ...

The system is going down for maintenance in 60 minutes!
Down in an hour

You do not have to quote the text after the number of minutes you provide shutdown. When cancelling a shutdown you can provide a message too.

Zelda
  • 6,158
  • 1
  • 21
  • 27