open.itworld.com
  Search  
Security Home Page Security Webcasts Security White Papers Security Newsletters Security News Open Topics Careers ITworld Voices ITwhirled The Security site of ITworld.com

Unix Tip: Viewing device aliases on the command line

ITworld.com 8/16/2007

Sandra Henry-Stocker, ITworld.com

Send in your Unix questions today! | See additional Unix tips and tricks

Ever wish you could take a look at the device aliases on a Solaris system without having to descend all the way down to the ok prompt? Well, you can. By issuing the proper version of the prtconf (print system configuration) command, you can include a list of device aliases in your prtconf output.

The prtconf command, often used to do such things as display the amount of memory installed on a system (e.g., "prtconf | grep Mem") and copious details on system devices and peripherals. It also includes a number of options that can change the amount and format of the information provided.

The -D option, for example, displays system peripherals in an indented (referred to as a "device tree") fashion that allows you to identify the relationships between devices. The -P option displays information about pseudo devices. The -x option reports whether or not a system is 64-bit ready.

To include information about your device aliases in your prtconf output, the combination of the -v and -p options (i.e., -vp) can be used. Given these options, the output will include a section which looks more or less like this:
        disk:  '/pci@1f,0/ide@d/disk@2,0'
        rtc:  '/pci@1f,0/isa@7/rtc@0,70'
        usb:  '/pci@1f,0/usb@a'
        flash:  '/pci@1f,0/isa@7/flashprom@1f,0'
        lom:  '/pci@1f,0/isa@7/SUNW,lomh@0,8010'
        i2c-nvram:  '/pci@1f,0/pmu@3/i2c@0,0/i2c-nvram@0,aa'
        net1:  '/pci@1f,0/ethernet@5'
        dload1:  '/pci@1f,0/ethernet@5:,'
        dload:  '/pci@1f,0/ethernet@c:,'
        net0:  '/pci@1f,0/ethernet@c'
        net:  '/pci@1f,0/ethernet@c'
        cdrom:  '/pci@1f,0/ide@d/cdrom@3,0:f'
        disk3:  '/pci@1f,0/ide@d/disk@3,0'
        disk2:  '/pci@1f,0/ide@d/disk@2,0'
        disk1:  '/pci@1f,0/ide@d/disk@1,0'
        disk0:  '/pci@1f,0/ide@d/disk@0,0'
        ide:  '/pci@1f,0/ide@d'
        floppy:  '/pci@1f,0/isa@7/dma/floppy'
        ttyb:  '/pci@1f,0/isa@7/serial@0,2e8'
        ttya:  '/pci@1f,0/isa@7/serial@0,3f8'
        name:  'aliases'
These lines represent the same device aliases that you would see if you were to issue the devalias command at the ok prompt.

To display this information while your system is in a normal operational state (like run state 3), you can issue the "prtconf -vp" command and page down to that portion that includes definitions like those shown above or you can use a script like the one I've included below to extract just those lines from the prtconf output.
#!/usr/bin/perl -w

@prtconf=`/usr/sbin/prtconf -vp`;
$e=0;

# find the end of the aliases section
foreach ( @prtconf ) {
    if ( /aliases/ ) {
        last;
    }
    $e++;
}

# find the start of the aliases section
for ( $s=$e-1; $s>1; $s-- ) {
    if ( $prtconf[$s]=~/^$/ ) {
        last;
    }
}

# display the aliases
for ( $i=$s+2; $i<=$e; $i++ ) {
    print "$prtconf[$i]";
}
This perl script works by looking for the last line in the output shown above -- the "name: 'aliases'" line. When it finds the line containing the word "aliases", it exits the foreach loop, leaving the line number in $e.

It then marches backward from $e toward the beginning of the file until it finds an empty line. While the output shown above doesn't make this obvious, the two lines preceding the desired information are a blank line followed by a line that starts with the word "Node" as shown below:
    Node 0xf002cb2c
        xnet2:  '/pci@1d,700000/pci@1/SUNW,hme@0,1:dhcp,'
        xnet1:  '/pci@1e,600000/pci@3/SUNW,hme@0,1:dhcp,'
When the script finds the blank line, it saves that line number in $s.

When the script finally readies to print the desired information, it sets the start point for the aliases output to $s incremented by two (see the last for loop) and prints each line up to and including the one referred to by $e (the end line).

Since this script detects the end of the aliases section and then searches upwards in the output for the start of that section, it is able to accommodate whatever number of devaliases are defined on a system. If you're not sure whether a mirror of your boot drive has been defined as a devalias or your boot disk is set up as disk or disk0, this script should make it easy for you to extract that information from your system.

On this topic

 

Sandra Henry-Stocker has been administering Unix systems for more than 18 years. She describes herself as "USL" (Unix as a second language) but remembers enough English to write books and buy groceries. She currently works for TeleCommunication Systems, a wireless communications company, in Annapolis, Maryland, where no one else necessarily shares any of her opinions. She lives with her second family on a small farm on Maryland's Eastern Shore. Send comments and suggestions to bugfarm@gmail.com.




Sponsored Links

Sign up for a Microsoft Dynamics® CRM WEBCAST
Hear globally recognized leaders in customer strategy discuss the importance and evolution of CRM.
Sun Microsystems' - FREE 60 DAY TRIAL OFFER!
Test Sun's Newest Servers BEFORE YOU BUY. Plug Them In With Access To Full Technical Support.
100% Web Based Help Desk Software
Easy to use, customizable to meet your needs, powerful and scalable. Free online demo. Try it today!
Sign up for a Microsoft Dynamics® CRM WEBCAST
Hear globally recognized leaders in customer strategy discuss the importance and evolution of CRM.
Used and Refurbished HP ProCurve Switches
Lifetime Warranties, Professional Testing & Shipping on all HP Equipment Purchases!
» Buy a link now

Advertisements
Sponsored links
Locate Hidden Software on business PCs with this free tool
Bring harmony to your mix of UNIX-Linux-Windows computing environments
Top 5 Reasons to Combine App Performance and Security
KODAK i1400 Series Scanners stand up to the challenge
 Home   Open source  Operating systems  Unix
www.itworld.com    open.itworld.com     security.itworld.com     smallbusiness.itworld.com
storage.itworld.com     utilitycomputing.itworld.com     wireless.itworld.com

 
Contact Us   About Us   Privacy Policy    Terms of Service   Reprints  

CIO   Computerworld   CSO   GamePro   Games.net   IDG Connect   IDG World Expo   Infoworld   ITworld   JavaWorld   LinuxWorld  MacUser   Macworld   Network World   PC World   Playlist  

Copyright © Computerworld, Inc. All rights reserved

Reproduction in whole or in part in any form or medium without express written permission of Computerworld Inc. is prohibited. Computerworld and Computerworld.com and the respective logos are trademarks of International Data Group Inc.