lshw, iwlist, dmidecode와 같은 일반적인 Unix 유틸리티의 텍스트 기반 출력을 구문 분석하는 프로그램/라이브러리가 없나요?

lshw, iwlist, dmidecode와 같은 일반적인 Unix 유틸리티의 텍스트 기반 출력을 구문 분석하는 프로그램/라이브러리가 없나요?

lshw.net 과 같은 하드웨어 데이터를 쿼리하기 위해 여러 UNIX 유틸리티를 사용하는 .net 핵심 응용 프로그램이 있습니다 iwlist. 출력이 지원되므로 문제가 되지 않습니다. 나는 현재 나만의 구문 분석 코드를 작성하고 있는데, 그러한 도구의 출력을 구문 분석할 수 있는 도구가 없다는 사실에 놀랐습니다.dmidecodelshwjson

내가 맞나요?

답변1

TxR느슨하게 구조화된 여러 줄의 텍스트에서 정보를 추출하는 언어입니다.

출력을 예로 들어 dmidecodeJSON 개체 목록으로 변환해 보겠습니다.

$ txr dmi-data.txr  dmi-data
{"Version":"VirtualBox","Address":"0xE0000","Characteristics":["ISA is supported","PCI is supported","Boot from CD is supported",
                                                               "Selectable boot is supported","8042 keyboard services are supported (int 9h)",
                                                               "CGA/mono video services are supported (int 10h)","ACPI is supported"],
 "desc":"BIOS Information","Vendor":"innotek GmbH","ROM Size":"128 kB",
 "Release Date":"12/01/2006","Runtime Size":"128 kB"}
{"Version":"1.2","Wake-up Type":"Power Switch","desc":"System Information",
 "SKU Number":"Not Specified","Manufacturer":"innotek GmbH","Serial Number":"0",
 "Product Name":"VirtualBox","Family":"Virtual Machine","UUID":"CE1C8E2B-F6C0-4E0B-9E40-7958B29D121F"}
{"Version":"1.2","desc":"Base Board Information","Features":["Board is a hosting board"],
 "Type":"Motherboard","Chassis Handle":"0x0003","Contained Object Handles":"0",
 "Manufacturer":"Oracle Corporation","Serial Number":"0","Asset Tag":"Not Specified",
 "Product Name":"VirtualBox","Location In Chassis":"Not Specified"}
{"Version":"Not Specified","desc":"Chassis Information","Boot-up State":"Safe",
 "Type":"Other","Security Status":"None","Manufacturer":"Oracle Corporation",
 "Lock":"Not Present","Serial Number":"Not Specified","Thermal State":"Safe",
 "Asset Tag":"Not Specified","Power Supply State":"Safe"}
{"desc":"OEM Strings","String 2":"vboxRev_140239","String 1":"vboxVer_6.1.14"}
{"desc":"OEM-specific Type","Header and Data":["80 08 08 00 2B C3 33 00"]}

프로그램은 다음과 같습니다:

# dmidecode @nil
@(skip)
Table at @nil

@(collect :vars (obj))
Handle @nil
@desc
@  (require (not (mequal desc "Inactive" "End Of Table")))
@  (bind obj @(hash))
@  (repeat :gap 0)
@    (cases)
@\t@prop: @value
@      (do (set [obj prop] value))
@    (or)
@\t@prop:
@      (collect :gap 0)
@\t@\t@valueline
@      (end)
@      (do (set [obj prop] (vec-list valueline)))
@    (end)
@  (until)
Handle @nil
@  (end)
@  (do (set [obj "desc"] desc))
@(end)
@(do (put-jsons obj))

dmi-data파일에는 다음이 포함됩니다.

# dmidecode 3.1
Getting SMBIOS data from sysfs.
SMBIOS 2.5 present.
10 structures occupying 450 bytes.
Table at 0x000E1000.

Handle 0x0000, DMI type 0, 20 bytes
BIOS Information
    Vendor: innotek GmbH
    Version: VirtualBox
    Release Date: 12/01/2006
    Address: 0xE0000
    Runtime Size: 128 kB
    ROM Size: 128 kB
    Characteristics:
        ISA is supported
        PCI is supported
        Boot from CD is supported
        Selectable boot is supported
        8042 keyboard services are supported (int 9h)
        CGA/mono video services are supported (int 10h)
        ACPI is supported

Handle 0x0001, DMI type 1, 27 bytes
System Information
    Manufacturer: innotek GmbH
    Product Name: VirtualBox
    Version: 1.2
    Serial Number: 0
    UUID: CE1C8E2B-F6C0-4E0B-9E40-7958B29D121F
    Wake-up Type: Power Switch
    SKU Number: Not Specified
    Family: Virtual Machine

Handle 0x0008, DMI type 2, 15 bytes
Base Board Information
    Manufacturer: Oracle Corporation
    Product Name: VirtualBox
    Version: 1.2
    Serial Number: 0
    Asset Tag: Not Specified
    Features:
        Board is a hosting board
    Location In Chassis: Not Specified
    Chassis Handle: 0x0003
    Type: Motherboard
    Contained Object Handles: 0

Handle 0x0003, DMI type 3, 13 bytes
Chassis Information
    Manufacturer: Oracle Corporation
    Type: Other
    Lock: Not Present
    Version: Not Specified
    Serial Number: Not Specified
    Asset Tag: Not Specified
    Boot-up State: Safe
    Power Supply State: Safe
    Thermal State: Safe
    Security Status: None

Handle 0x0007, DMI type 126, 42 bytes
Inactive

Handle 0x0005, DMI type 126, 15 bytes
Inactive

Handle 0x0006, DMI type 126, 28 bytes
Inactive

Handle 0x0002, DMI type 11, 7 bytes
OEM Strings
    String 1: vboxVer_6.1.14
    String 2: vboxRev_140239

Handle 0x0008, DMI type 128, 8 bytes
OEM-specific Type
    Header and Data:
        80 08 08 00 2B C3 33 00

Handle 0xFEFF, DMI type 127, 4 bytes
End Of Table

관련 정보