如何讓server的螢幕關閉電源? - Linux

Steve avatar
By Steve
at 2010-12-24T17:39

Table of Contents

注意!!! 請確認你沒有啟動 X 再嘗試以下動作

請參考 man console_codes 其中這段:

Linux Console Private CSI Sequences

The following sequences are neither ECMA-48 nor native VT102. They are
native to the Linux console driver. Colors are in SGR parameters: 0 =
black, 1 = red, 2 = green, 3 = brown, 4 = blue, 5 = magenta, 6 = cyan,
7 = white.

ESC [ 1 ; n ] Set color n as the underline color
ESC [ 2 ; n ] Set color n as the dim color
ESC [ 8 ] Make the current color pair the default attributes.
ESC [ 9 ; n ] Set screen blank timeout to n minutes.
ESC [ 10 ; n ] Set bell frequency in Hz.
ESC [ 11 ; n ] Set bell duration in msec.
ESC [ 12 ; n ] Bring specified console to the front.
ESC [ 13 ] Unblank the screen.
ESC [ 14 ; n ] Set the VESA powerdown interval in minutes.

請以 root 的權限執行以下命令:

echo -e "\033[9;1]" > /dev/console
echo -e "\033[14;1]" > /dev/console

之後閒置一分鐘, 畫面會變黑, 再過一分鐘, 螢幕關機.
或者也可以試試 setterm, 詳細請 man setterm 尋找其中 VESA 段落.

以上兩種方法其實都是透過 kernel DPMS 來關閉螢幕, 很不幸的
網路上看到許多回報 screen blank 正常, screen powerdown 沒有作用,
我不確定這是 kernel 的 bug 或是硬體的問題.

如果你也屬於有問題的一員, 請再試試以下方法:
使用 vbetool 關閉螢幕( vbe 是 VESA BIOS Extension 的縮寫)
請注意最後這個方法並不是設定一個閒置的時間自動關閉螢幕,
也就是以 vbetool 關閉螢幕就要摸黑操作了.
我的解決辦法是連結到 Alt-UpArrow 功能鍵, 把以下內容存到 /usr/sbin/dpms

#!/bin/bash
touch /var/dpms
state=$(< /var/dpms)
case "$state" in
off) state=on ;;
*) state=off ;;
esac
echo $state > /var/dpms
vbetool $state

修改 /etc/inittab 加入以下這行

kb::kbrequest:/usr/sbin/dpms

執行 telinit q 使新的 inittab 生效, 之後就可以按 Alt-UpArrow 開關螢幕了

※ 引述《uwmtsa5566 (名人)》之銘言:
: 我灌了一部Ubuntu Server
: 只跑 text console
: 發現這部主機的螢幕會一整天都在亮
: 就算很久一段時間沒動
: 畫面只是變黑
: 並沒有關閉螢幕電源
: 像這種當server用的主機
: 希望設定一段時間之後
: 能自動關閉螢幕電源
: 該怎麼做?

--
A quotation from the movie "The Se7en":
Ernest Hemingway once wrote that,
"The world is a fine place and worth fighting for."
I agree with the second part.

--
Tags: Linux

All Comments

lenny直上squeeze,讓我差點以為收藏都掰了.

Madame avatar
By Madame
at 2010-12-24T10:36
文章很長,本人又很A,裡面滿滿的怨念,看完一定不能解決你的問題. 所以你要是想看技術相關類型,請按下 andlt;- ,在找別的文章. 人都跑了嗎? 什麼,你還是要留下來? 那準備好接受我的善液吧!喝!jizz~ /****************************本文開始************ ...

isz

Rebecca avatar
By Rebecca
at 2010-12-24T09:39
請問有 isz 轉 iso 的指令嗎? 或著有像 7z 可以解開 iso 一樣的程式可以解開 isz 的? - ...

在windows下使用ubuntu的環境來寫程式

Dora avatar
By Dora
at 2010-12-24T01:44
標題下得不好,請見諒。最近在學程式,(c, python, gtk+ 2.0),很喜歡在 ubuntu 下 用 terminal 寫程式的感覺。但因為一些原因,常常還是比較希望開windows (不用virtual machine)。所以想知道是否在windows 下能安裝某些東西,能夠 使用類似於 u ...

CentOS 5.5 useradd 出現command not found

Agnes avatar
By Agnes
at 2010-12-24T00:53
大家好 我安裝centos5.5 然後使用sudo useradd user這個指令時 出現command not found訊息 突然覺得很意外 結果我到/usr/sbin/裡面 用sudo ./useradd 就可以執行了 ...

支援Unicode的 FTP server?

Dora avatar
By Dora
at 2010-12-24T00:51
請問常見的ftp server套件軟體 vsftpd、proftpd、wu ftp 這三套 都是支援Unicode嗎? - ...