Shutdown

更改關機廣播消息

  • November 27, 2013

是否可以將廣播的預設消息更改shutdown為其他內容?

正如@Zelda提到的,這些消息是硬編碼的。如果您想更改它而不是使用附加位修改消息:

$ sudo shutdown -h +120 Save your work.

您需要重新編譯shutdown,創建您自己的包含自定義消息的執行檔。

例如,這是一個範例源文件 shutdown.c。需要更改諸如此類的行,並且需要重建 .c 文件。

/*
*      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);
}

引用自:https://unix.stackexchange.com/questions/102713