Thursday, 18 April 2013

Find that long lost AIX SMIT menu you can't seem to get back to

SMIT is one of the nicest features of AIX.   It provides an extremely easy to use interface to manage almost every aspect of an AIX system.

One of the only problems with SMIT is that it is so inclusive and complete that the menu system is huge and it can be hard to find things in the menu.   There have been times where I was in SMIT and found a really useful menu, but then the next time I went to use that same menu I couldn't find it again!

I started playing around with the idea of writing a script to read the ODM and display a "tree-view" of the entire SMIT menu/sub-menus.    When I got it to work, I was shocked at the size of the SMIT menu system and everything it includes.   SMIT really is an incredible tool and includes a TON of useful stuff in it.

This script will show every menu/sub-menu in a tree view.   It also shows the fast-path to get directly to each menu.   The fast-path is a SMIT "shortcut".   For example, to get to the SMIT filesystems menu directly from the command line you can use the "fs" fast-path by typing "smit fs" on the command line.

Here is a screenshot of the first few lines of the output of the script.   On my system the total output of the script showing the complete SMIT menu is 4,805 lines!  

The text in the brackets "[ ]" is the fast-path to get directly to that menu.

You can either "grep" the output of the script to search for something in the SMIT menu system, or you could redirect the output to a file, and then open the file with your favorite text editor and search through it to find parts of SMIT you are looking for.  

It is also very educational to just look through the output.   Just by glancing through it I've found several things SMIT can do that I wasn't aware of.

Here is the script.  It can be run as a regular user and the only external command it runs is "ODMDIR=/usr/lib/objrepos; odmget sm_menu_opt"
#Brian Smith, 4/12/13
#Show a tree view of entire smit menu system and show fast paths
use strict;

my (@odmdata, @odmstanza, $odmrecord, $line, $id, $next_id, $indent);
my ($id_seq_num, $text, %sm_menu_opt, $key, $next_type, $key2);

local $/ = "sm_menu_opt:";
@odmdata = `ODMDIR=/usr/lib/objrepos; odmget sm_menu_opt`;

for $odmrecord (@odmdata){
        my @odmstanza = split "\n", $odmrecord;
        $text = $id_seq_num = $next_id = $id = $next_type = "";
        for $line (@odmstanza){
                chomp $line;
                if ($line =~ /\tid = "(.*)"/) { $id = $1; }
                if ($line =~ /\tnext_id = "(.*)"/) { $next_id = $1; }
                if ($line =~ /\tnext_type = "(.*)"/) { $next_type = $1; }
                if ($line =~ /\tid_seq_num = "(.*)"/) { $id_seq_num = $1; }
                if ($line =~ /\ttext = "(.*)"/) { $text = $1; }
        $key = "$id.$id_seq_num";
        push (@{$sm_menu_opt{$key}}, $id, $id_seq_num, $next_id, $next_type, $text);


sub getnext {
        my $next = $_[0];
        my %sorthash = ();
        foreach $key (keys %sm_menu_opt){
                if (@{$sm_menu_opt{$key}}[0] eq "$next"){
                        push (@{$sorthash{$key}}, @{$sm_menu_opt{$key}}[0]);
                        push (@{$sorthash{$key}}, @{$sm_menu_opt{$key}}[1]);
                        push (@{$sorthash{$key}}, @{$sm_menu_opt{$key}}[2]);
                        push (@{$sorthash{$key}}, @{$sm_menu_opt{$key}}[3]);
                        push (@{$sorthash{$key}}, @{$sm_menu_opt{$key}}[4]);

        foreach $key2 (sort {$sorthash{$a}[1] <=> $sorthash{$b}[1] } keys %sorthash){
                if (@{$sorthash{$key2}}[2] ne ""){
                        print "${indent}---@{$sorthash{$key2}}[4] [@{$sorthash{$key2}}[2]]\n";
                        print "${indent}---@{$sorthash{$key2}}[4]\n";
                if (@{$sorthash{$key2}}[3] eq "m") {
                        $indent .= "   |";
                        substr($indent, 0, 4) = "";

0 blogger-disqus:

Post a Comment