Linux는 모니터가 연결되어 있는지 명령줄에서 알 수 있습니까?

Linux는 모니터가 연결되어 있는지 명령줄에서 알 수 있습니까?

나는 명령줄에서 모니터가 컴퓨터에 연결되어 있는지 여부를 알 수 있기를 원합니다(그래서 X가 실행되어야 하는지 여부를 스크립트에서 결정할 수 있습니다). 어떻게 해야 합니까?

나는 X의 존재에 의존할 수 없으므로 xrandr. 내가 발견했다ddccontrol, 그러나 그 출력은 여러 줄이며 구문 분석하기 쉽지 않습니다. (정보가 이론적으로 내가 원하는 방식으로 이용 가능하다는 것을 말해줍니다.) 모니터가 시스템에 연결되어 있는지 알려줄 수 있는 스크립트 친화적인 프로그램이 있습니까?

내가 이것을 실행하고 싶은 대부분의 시스템은 Fedora 20을 실행하고 있습니다.

답변1

Fedora 20에서는 이것을 시도하지 않았지만 (Ubuntu 13.04에서만) 내 머릿속 이론은 타당합니다.

read-edid를 사용해 볼 수 있습니다(http://www.polypux.org/projects/read-edid/)

XF86 호환 모델라인을 제공해야 합니다. 구문 분석할 수 있습니다.

하도록 하다~할 것 같다일하다. 아마도 훨씬 더 쉽고 종료 코드를 확인할 수도 있습니다.

$ sudo get-edid > edid
get-edid: get-edid version 2.0.0

    Performing real mode VBE call
    Interrupt 0x10 ax=0x4f00 bx=0x0 cx=0x0
    Function supported
    Call successful

    VBE version 300
    VBE string at 0x11100 "NVIDIA"

VBE/DDC service about to be called
    Report DDC capabilities

    Performing real mode VBE call
    Interrupt 0x10 ax=0x4f15 bx=0x0 cx=0x0
    Function supported
    Call successful

    Monitor and video card combination does not support DDC1 transfers
    Monitor and video card combination supports DDC2 transfers
    0 seconds per 128 byte EDID block transfer
    Screen is not blanked during DDC transfer

Reading next EDID block

VBE/DDC service about to be called
    Read EDID

    Performing real mode VBE call
    Interrupt 0x10 ax=0x4f15 bx=0x1 cx=0x0
    Function supported
    Call failed

The EDID data should not be trusted as the VBE call failed
EDID claims 255 more blocks left
EDID blocks left is wrong.
Your EDID is probably invalid.
tom@tom:~$ parse-edid < edid 
parse-edid: parse-edid version 2.0.0
parse-edid: EDID checksum failed - data is corrupt. Continuing anyway.
parse-edid: first bytes don't match EDID version 1 header
parse-edid: do not trust output (if any).

    # EDID version 255 revision 255
Section "Monitor"
    Identifier "___:ffff"
    VendorName "___"
    ModelName "___:ffff"
    # DPMS capabilities: Active off:yes  Suspend:yes  Standby:yes

    Mode    "4095x4095" # vfreq 9.770Hz, hfreq 80.018kHz
        DotClock    655.350000
        HTimings    4095 4350 4605 8190
        VTimings    4095 4158 4221 8190
        Flags   "Interlace" "+HSync" "+VSync"
    EndMode
    Mode    "4095x4095" # vfreq 9.770Hz, hfreq 80.018kHz
        DotClock    655.350000
        HTimings    4095 4350 4605 8190
        VTimings    4095 4158 4221 8190
        Flags   "Interlace" "+HSync" "+VSync"
    EndMode
    Mode    "4095x4095" # vfreq 9.770Hz, hfreq 80.018kHz
        DotClock    655.350000
        HTimings    4095 4350 4605 8190
        VTimings    4095 4158 4221 8190
        Flags   "Interlace" "+HSync" "+VSync"
    EndMode
    Mode    "4095x4095" # vfreq 9.770Hz, hfreq 80.018kHz
        DotClock    655.350000
        HTimings    4095 4350 4605 8190
        VTimings    4095 4158 4221 8190
        Flags   "Interlace" "+HSync" "+VSync"
    EndMode
EndSection

답변2

다음을 사용하여 현재 연결되어 있거나 "알려진" 디스플레이와 같은 정보를 나열할 수 있습니다 xrandr.

# list all known monitors
xrandr --listmonitors --verbose

# list active monitors
xrandr --listactivemonitors

약간의 grepping을 사용하면 이것이 작동합니다. man사용 사례에 더 나은 기능이 있는지 확인하려면 페이지를 살펴보는 것이 좋습니다 .

이것이 제가 스크립트에 가장 유용하다고 생각한 것입니다.

xrandr | grep " connected " # =>
  # eDP-1
  # HDMI-1 # <-- the monitor I want to detect

# AND -- to check if `HDMI-1` is connected
xrandr | grep " connected " | awk '{ print$1 }' | grep HDMI-1

# store connection status in a var
$hdmi_connection=$(xrandr | grep " connected " | awk '{ print$1 }' | grep HDMI-1)

관련 정보