SQLite

Remote Desktop 将收集的信息储存在 SQLite 数据库中。

关于数据库

Remote Desktop 将系统信息数据捕捉到称为“systeminformation”的表格中。它不保存历史数据。无论何时收集数据,新值都将覆盖之前采集的信息。如果您想保留历史数据,您可以将数据采集到第二个数据库。数据库中的数据还可以用于帮助进行 OS X 部署,因为应用程序可以根据数据库中的值访问电脑记录或同步机器特定设置。

在实际应用中,您应该将数据库视为只读。数据库结构可能会更改,以满足较新版本的 Remote Desktop 的需求。或者,在某些情况下,Remote Desktop 将清除数据库,以防止损坏。

SQLite 数据库位于“/private/var/db/RemoteManagement/RMDB/rmdb.sqlite3”。RMDB 目录对于守护程序用户具有限制,因此需要超级用户 (sudo) 访问权限才能访问这些文件。在命令前面使用 sudo 时,系统将提示您输入管理员密码。

使用命令行取回数据

sqlite3 工具安装在“/usr/bin/sqlite3”中。

sqlite3 工具提供 Remote Desktop 数据库中表格和数据的访问权限。以下脚本发送 SQL 查询以查询“systeminformation”表格(储存报告数据的表格)。

sudo sqlite3 /var/db/RemoteManagement/RMDB/rmdb.sqlite3 "select * from systeminformation"

以下是输出前几行的示例。这些行可以换行,具体取决于字体和窗口大小。

00:0d:93:9c:0a:e4|Mac_HardDriveElement|DataDate|0|2008-12-11T23:05:58Z|2008-12-11T23:05:58Z00:0d:93:9c:0a:e4|Mac_HardDriveElement|Model|0|Hitachi HDS722580VLSA80|2008-12-11T23:05:58Z00:0d:93:9c:0a:e4|Mac_HardDriveElement|VolumeName|0|Server HD|2008-12-11T23:05:58Z00:0d:93:9c:0a:e4|Mac_HardDriveElement|JournalingIsActive|0|true|2008-12-11T23:05:58Z00:0d:93:9c:0a:e4|Mac_HardDriveElement|LastBackupDate|0|2008-09-05T18:13:22Z|2008-12-11T23:05:58Z00:0d:93:9c:0a:e4|Mac_HardDriveElement|LastModificationDate|0|2008-12-11T23:05:57Z|2008-12-11T23:05:58Z

使用 -separator 开关调整栏之间使用的分隔符。此示例使用逗号分隔符。

sudo sqlite3 -separator , /var/db/RemoteManagement/RMDB/rmdb.sqlite3 "select * from systeminformation"

其他现有开关包括 -html-line-list-column。有关更多详细信息,请参阅 sqlite3 的 man 页面。

此命令将以可读性很强的栏输出并显示栏标头。

sudo sqlite3 -header -column /var/db/RemoteManagement/RMDB/rmdb.sqlite3 "select * from systeminformation"ComputerID ObjectName PropertyName ItemSeq Value LastUpdated----------------- -------------------- ------------ ---------- -------------------- --------------------00:0d:93:9c:0a:e4 Mac_HardDriveElement DataDate 0 2008-12-11T23:05:58Z 2008-12-11T23:05:58Z00:0d:93:9c:0a:e4 Mac_HardDriveElement Model 0 Hitachi HDS722580VLS 2008-12-11T23:05:58Z00:0d:93:9c:0a:e4 Mac_HardDriveElement VolumeName 0 Server HD 2008-12-11T23:05:58Z00:0d:93:9c:0a:e4 Mac_HardDriveElement JournalingIs 0 true 2008-12-11T23:05:58Z00:0d:93:9c:0a:e4 Mac_HardDriveElement LastBackupDa 0 2008-09-05T18:13:22Z 2008-12-11T23:05:58Z00:0d:93:9c:0a:e4 Mac_HardDriveElement LastModifica 0 2008-12-11T23:05:57Z 2008-12-11T23:05:58Z00:0d:93:9c:0a:e4 Mac_HardDriveElement TotalSize 0 80287128.000000 2008-12-11T23:05:58Z

ComputerID 栏与回复报告数据的客户端的以太网 MAC 地址匹配,因此可以用作唯一值来形成 SQL 查询。若要看到所有对象名称类型,请将上述示例中的 SQL 修改为如下形式:

sudo sqlite3 -header -column /var/db/RemoteManagement/RMDB/rmdb.sqlite3 "SELECT distinct objectname FROM systeminformation"

输出:

ObjectName--------------------Mac_HardDriveElementMac_NetworkInterfaceMac_SystemInfoElemenMac_RAMSlotElementMac_PCIBusElementMac_USBDeviceElementMac_FireWireDeviceEl

对于每个对象名称,存在很多可能的属性名称值。正在修改您的查询提供可用对象名称/属性名称对:

sudo sqlite3 -header -column /var/db/RemoteManagement/RMDB/rmdb.sqlite3 "SELECT distinct objectname, propertyname FROM systeminformation"

输出:

ObjectName PropertyName-------------------- ------------Mac_HardDriveElement DataDateMac_HardDriveElement ModelMac_HardDriveElement VolumeNameMac_HardDriveElement JournalingIsMac_HardDriveElement LastBackupDaMac_HardDriveElement LastModifica

这些属性将合并,以帮助您形成可取回特定值的 SQL 查询。例如,若要查找客户端序列号,您可以使用:

sudo sqlite3 -header -column /var/db/RemoteManagement/RMDB/rmdb.sqlite3 "SELECT distinct computerid, propertyname, value FROM systeminformation WHERE propertyname = 'MachineSerialNumber'"ComputerID PropertyName Value----------------- ------------------- -----------00:0d:93:9c:0a:e4 MachineSerialNumber QP4241FHPMZ00:16:cb:a2:6d:1b MachineSerialNumber YM6090M9U3900:16:cb:ca:81:52 MachineSerialNumber W862100NW9200:17:f2:04:db:24 MachineSerialNumber G86492DVX6800:14:51:22:28:38 MachineSerialNumber W854503QURC00:17:f2:2b:b9:59 MachineSerialNumber 4H63861KVMM

您可以让 SQL 查询获取包含电脑名称(而不是以太网 ID)和值的列表:

sudo sqlite3 -header -column /var/db/RemoteManagement/RMDB/rmdb.sqlite3 "SELECT R1.value, R2.value FROM systeminformation R1, systeminformation R2 WHERE R1.computerid=R2.computerid AND R1.propertyname='ComputerName' AND R2.propertyName='MachineSerialNumber'"

输出:

Value Value---------- -----------Xserve QP4241FHPMZmini YM6090M9U39NetBoot001 W862100NW92Server G86492DVX68Server2 W854503QURCWendy G 4H63861KVMM

将 Automator 与 sqlite 命令配合使用

由于 Automator 可以执行 Shell 命令,因此可以将其用于收集 sqlite3 输出并将输出发送给其他应用程序。此示例收集了报告数据并将其发送给“文本编辑”:

on run {input, parameters}return do shell script "/usr/bin/sqlite3 -separator " & quote & tab & quote & " /var/db/RemoteManagement/RMDB/rmdb.sqlite3 " & quote & input & quote with administrator privilegesend run

此工作流程将提示输入 SQL 命令,然后使用“运行 AppleScript”操作构建 Shell 命令,而这会弹出鉴定对话框。此示例中的分隔符是制表符。

请求 SQL 查询并执行它的 Automator 工作流程的屏幕快照。

sqlite 查询项

Mac_HardDriveElement

CreationDate

DataDate

FileSystemType

FreeSpace

GroupName

IsBootVolume

IsCasePreserving

IsCaseSensitive

IsDetachable

IsWritable

JournalingIsActive

LastBackupDate

LastConsistencyCheckDate

LastModificationDate

LogicalUnitNumber

Manufacturer

Model

OwnerName

PermissionModes

PermissionsAreEnabled

Protocol

RemovableMedia

Revision

SerialNumber

SupportsJournaling

TotalFileCount

TotalFolderCount

TotalSize

UnixMountPoint

VolumeName

Mac_NetworkInterfaceElement

AllDNSServers

AllIPAddresses

ConfigurationName

ConfigurationType

DataDate

EthernetAlignmentErrors

EthernetCarrierSenseErrors

EthernetChipSet

EthernetCollisionFrequencies

EthernetDeferredTransmissions

EthernetExcessiveCollisions

EthernetFCSErrors

EthernetFrameTooLongs

EthernetInternalMacRxErrors

EthernetInternalMacTxErrors

EthernetLateCollisions

EthernetMissedFrames

EthernetMultipleCollisionFrames

EthernetRxCollisionErrors

EthernetRxFrameTooShorts

EthernetRxInterrupts

EthernetRxOverruns

EthernetRxPHYTransmissionErrors

EthernetRxResets

EthernetRxResourceErrors

EthernetRxTimeouts

EthernetRxWatchdogTimeouts

EthernetSingleCollisionFrames

EthernetSQETestErrors

EthernetTxInterrupts

EthernetTxJabberEvents

EthernetTxPHYTransmissionErrors

EthernetTxResets

EthernetTxResourceErrors

EthernetTxTimeouts

EthernetTxUnderruns

HardwareAddress

InterfaceFlags

InterfaceName

IsActive

IsPrimary

NetworkCollisions

NetworkInputErrors

NetworkInputPackets

NetworkOutputErrors

NetworkOutputPackets

OutputQueueCapacity

OutputQueueDropCount

OutputQueueOutputCount

OutputQueuePeakSize

OutputQueueRetryCount

OutputQueueSize

OutputQueueStallCount

PrimaryDNSServer

PrimaryIPAddress

RouterAddress

Mac_SystemInfoElement

ActiveProcessorCount

AppleTalkIsActive

ATADeviceCount

BootROMVersion

BusDataSize

BusSpeed

BusSpeedString

ComputerName

DataDate

En0Address

FileSharingIsEnabled

FireWireDeviceCount

FTPIsEnabled

HasKeyboardConnected

HasLightsOutController

HasMouseConnected

HasVectorProcessingUnit

KernelVersion

Level2CacheSize

MachineClass

MachineIsNetBooted

MachineModel

MachineSerialNumber

MainMonitorDepth

MainMonitorHeight

MainMonitorType

MainMonitorWidth

ModemDescription

ModemDriverInfo

ModemInstalled

ModemInterfaceType

OpticalDriveType

PCISlotsUsedCount

PhysicalMemorySize

PrimaryIPAddress

PrimaryNetworkCollisions

PrimaryNetworkFlags

PrimaryNetworkHardwareAddress

PrimaryNetworkInputErrors

PrimaryNetworkInputPackets

PrimaryNetworkOutputErrors

PrimaryNetworkOutputPackets

PrimaryNetworkType

PrinterSharingEnabled

ProcessorCount

ProcessorSpeed

ProcessorSpeedString

ProcessorType

RemoteAppleEventsEnabled

RemoteLoginEnabled

SCSIDeviceCount

SleepDisplayWhenInactive

SleepWhenInactive

SpinDownHardDrive

SystemVersion

SystemVersionString

TotalFreeHardDriveSpace

TotalHardDriveSpace

TotalRAMSlots

TotalSwapFileSize

TrashSize

UnixHostName

UnusedRAMSlots

USBDeviceCount

UserMemorySize

WakeOnLanEnabled

WebSharingIsEnabled

WindowsFileSharingEnabled

WirelessCardInstalled

Mac_RAMSlotElement

DataDate

MemoryModuleSize

MemoryModuleSpeed

MemoryModuleType

SlotIdentifier

Mac_PCIBusElement

CardMemory

CardName

CardRevision

CardType

DataDate

DeviceID

RomRevision

SlotName

VendorID

Mac_NetworkInterfaceElement

DomainName

Mac_SystemInfoElement

WirelessCardFirmwareVersion

WirelessCardHardwareAddress

WirelessCardIsActive

WirelessCardLocale

WirelessCardType

Mac_USBDeviceElement

BusPower

DataDate

DeviceSpeed

ProductID

ProductName

SerialNumber

VendorID

Mac_SystemInfoElement

WirelessNetworkAvailable

Mac_FireWireDeviceElement

DataDate

DeviceSpeed

Manufacturer

Model

Mac_SystemInfoElement

ARDComputerInfo1

ARDComputerInfo2

ARDComputerInfo3

ARDComputerInfo4

ModemCountryInfo

SelectedPrinterName

SelectedPrinterPostScriptVersion

SelectedPrinterType

WirelessChannelNumber

WirelessIsComputerToComputer

WirelessNetworkName