MagniComp Home Page Know IT allTM
May 16, 2008 Home Customer Services Pricing Downloads Support Contact Us
SysInfo
Related
Products
SysInfoTM
Total system and storage asset inventory information for Linux, Mac, UNIX, and Windows.
 
StorSys ProTM
Total SAN/NAS Storage System information.TM
 
RDist
Remote software distribution system.
Search
 

SysInfo Solutions Center

Simple Perl SysInfo Parser

Perl is an ideal way to parse SysInfo data. You have two choices for using getting SysInfo data into Perl. The first is to use the SysInfo Perl API. The second is to write your own simple parser in Perl. If you need basic data such as system model, memory, list of disks, etc, then a simple parser as described here is probably easier than learning the SysInfo Perl API.

When the --format report option is used, the data requested will be in a field deliminated format which is easy to parse. By default the deliminated string used is " | " (SPACE Vertical-Pipe SPACE). Here is some sample, truncated output for class general:

appname|Application Name|SysInfo
appversion|Application Version|6.0 H2
general||hostname|Host Name|dune.magnicomp.com
general||hostaliases|Host Aliases|dune localhost.localdomain
general||hostaddrs|Host Address(es)|127.0.0.1
general||hostid|Host ID|007f0100
general||man|Manufacturer|Dell Corporation
general||manshort|Manufacturer (Short)|Dell
general||manlong|Manufacturer (Full)|Dell Corporation
general||model|System Model|Dimension 4500
general||memory|Main Memory|512 MB
...

The following perl program will run SysInfo, parse the output and report the system model and amount of system memory (RAM).

#!/usr/bin/perl

#
# Location of SysInfo command.
#
my $SysInfoCmd = "/opt/sysinfo/bin/mcsysinfo";

#
# Build command ARRAY.
#
my @Cmd;
push(@Cmd, $SysInfoCmd);
push(@Cmd, "--format");
push(@Cmd, "report");		# Output parsable data
push(@Cmd, "--class");
push(@Cmd, "general");		# Limit data to General system info
push(@Cmd, "--repsep");
push(@Cmd, "%p");		# Use | as field deliminator

#
# Global variables
#
my $SysModel;
my $SysMemory;

#printf "Running %s\n", join(' ', @Cmd);

if (!open(CMD, '-|', @Cmd)) {
    printf stderr ("Failed to open command %s", join(' ', @Cmd));
    exit 1;
}

while (my $Line = <CMD>) {
    chomp($Line);
    my @Argv = split('\|', $Line);

    if (lc($Argv[0]) =~ 'general') {	# Class field
	if (lc($Argv[2]) =~ 'model') {	# Keyword field
	    $SysModel = $Argv[4];
	} elsif (lc($Argv[2]) =~ 'memory') {
	    $SysMemory = $Argv[4];
	}
    }
}

close(CMD);

printf "System Model is %s with %s memory\n", $SysModel, $SysMemory;
exit(0);

When the above program is run, you will see output like:

System Model is Dimension 4500 with 512 MB memory


Current: 8
All Releases
Let us know what's on your mind! Send us feedback
May 1, 2008: AIX 6.1 and Windows Server 2008 are now supported with version 8-H10 and later. Download

Feb 4, 2008: SysInfo 8 is a major new release now available featuring support for Software Discovery LanguageTM, enhanced BIOS, and much more. (More...) Download

Oct 30, 2006: SysInfo 7.0.1 release contains multiple bug fixes and is recommend for all version 7 customers. (More...) Download

Aug 8, 2006: SysInfo 7 GA is a major new release now available featuring support for Virtual Machines, System Services, Patches, and much more. (More...) Download
Want to Receive Announcements?
If you wish to receive announcements about new releases of SysInfo, please Register with us.
© Copyright 1992-2008 MagniComp