<?xml version="1.0" encoding="windows-1252"?>
<node id="1002703" title="devtree on AIX" created="2012-11-07 12:58:35" updated="2012-11-07 12:58:35">
<type id="1042">
CUFP</type>
<author id="632766">
eddor1614</author>
<data>
<field name="doctext">
&lt;p&gt;I've been looking for a command or script for AIX similar to lspci -t on Linux, a sort of Device tree &lt;/p&gt;
&lt;p&gt;I didn't find it, although there are a few using shell script.&lt;/p&gt;
&lt;p&gt;I've made a simple one using Perl, recursion and just one call to lsdev.&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;
#!/usr/bin/perl

use warnings;
use strict;

my $base = defined($ARGV[0]) ? $ARGV[0] : "ALL!";

if (defined($ARGV[0]) and $ARGV[0] eq "-h") {
    usage();
    exit;
}

sub usage {
    print qq($/Usage:$/$/);
    print qq($0 [base]    - "base is optional and defaults to sys0$/$/);
    print qq(This script builds a tree of devices$/$/);
}

my %devices = map { chomp; s/,$/,_/; split /,/,$_ } (`lsdev -F name,parent`);

sub children {
    my $parent = shift;
    my @lsdev;
    foreach (keys %devices) {
        push @lsdev, $_ if $devices{$_} eq $parent;
    }
    return @lsdev;
}

sub graph {
    my $step = shift;
    my @lista = @_;
    foreach my $i (@lista) {
        print "|", " " x $step,"|-- ",$i,$/;
        graph($step+3,children($i));
    }
}

if ($base eq "ALL!") {
    graph(0,children("_"));
} else {
    graph(0,$base);
}

&lt;/code&gt;
&lt;/p&gt;</field>
</data>
</node>
