在Linux服務(wù)器關(guān)機(jī)前向用戶顯示一條自定義消息
在先前的文章中,我們解釋了 Linux 中 shutdown、poweroff、halt、reboot 命令的不同之處,并揭示了在用不同的選項(xiàng)執(zhí)行這些命令時(shí)它們實(shí)際做了什么。
本篇將會(huì)向你展示如何在系統(tǒng)關(guān)機(jī)時(shí)向所有的系統(tǒng)用戶發(fā)送一條自定義的消息。
建議閱讀:tuptime - 顯示 Linux 系統(tǒng)的歷史和統(tǒng)計(jì)運(yùn)行時(shí)間
作為一名系統(tǒng)管理員,在你關(guān)閉服務(wù)器之前,你也許想要發(fā)送一條消息來警告他們系統(tǒng)將要關(guān)閉。默認(rèn)上,shutdown 命令會(huì)如下所示給其他系統(tǒng)用戶廣播這條信息:
- # shutdown 13:25
Linux 關(guān)機(jī)操作廣播消息
- Shutdown scheduled for Fri 2017-05-12 13:25:00 EAT, use 'shutdown -c' to cancel.
- Broadcast message for root@tecmint (Fri 2017-05-12 13:23:34 EAT):
- The system is going down for power-off at Fri 2017-05-12 13:25:00 EAT!
要在 shutdown 那行發(fā)送一條自定義的消息給其他系統(tǒng)用戶,運(yùn)行下面的命令。在本例中,關(guān)閉會(huì)在命令執(zhí)行后的兩分鐘之后發(fā)生。
- # shutdown 2 The system is going down for required maintenance. Please save any important work you are doing now!
Linux 系統(tǒng)關(guān)閉消息
假設(shè)你有一些關(guān)鍵的系統(tǒng)操作,如計(jì)劃系統(tǒng)備份或更新會(huì)在系統(tǒng)關(guān)閉的時(shí)候進(jìn)行,如下所示,你可以使用 -c 選項(xiàng)取消關(guān)機(jī),并在執(zhí)行玩這些操作后繼續(xù)執(zhí)行:
- # shutdown -c
Linux 關(guān)機(jī)操作取消消息:
- Shutdown scheduled for Fri 2017-05-12 14:10:22 EAT, use 'shutdown -c' to cancel.
- Broadcast message for root@tecmint (Fri 2017-05-14 :10:27 EAT):
- The system shutdown has been cancelled at Fri 2017-05-12 14:11:27 EAT!
另外,學(xué)習(xí)如何在 Linux 中使用簡單和傳統(tǒng)的方法在重啟或者開機(jī)時(shí)自動(dòng)執(zhí)行命令/腳本。
不要錯(cuò)過:
現(xiàn)在你知道了如何在系統(tǒng)關(guān)閉前向其他系統(tǒng)用戶發(fā)送自定義消息了。你有其他關(guān)于這個(gè)主題想要分享的想法么?何不使用下面的評(píng)論欄?