System Model in a shell script

If you have a UNIX shell script and wish to obtain the system model or similiar data via SysInfo, you can use the shell double backtic (``) to get this information from SysInfo. The follow sample sh(1) script gets the system model and prints it out:


model=`/opt/sysinfo/bin/sysinfo --show model`
echo "System Model is $model"
exit 0

This same method can easily be used to obtain similiar information such as system memory, CPU Model, CPU Speed, etc. To see a list of arguments valid for use with --show run the command:

/opt/sysinfo/bin/sysinfo --nw --list show

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|
general||hostaliases|Host Aliases|dune localhost.localdomain
general||hostaddrs|Host Address(es)|
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).


# 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 = ) {
    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];


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

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

System Model is Dimension 4500 with 512 MB memory

Update /etc/motd with system information

If you wish to automatically update the UNIX /etc/motd file with system information, try using the mcsysinfomotd which is bundled with SysInfo. When you run it, it will insert/update 2 lines of /etc/motd and will look something like:

host% cat /etc/motd

OS Release is Fedora Core 4 (Linux 2.6.11-1.1369_FC4)

System is a Dell DIM4500, 1 x 2.4 GHz Pentium 4, 512 MB RAM

You must run mcsysinfomotd as a user who has write permissions to the /etc directory. Usually this means you must be root.

Typically you want to run mcsysinfomotd whenever the system boots via an /etc/init.d file or equivilant.