Tuesday 19 March 2013

Top 10 AIX Commands


This article gives you the top 10 uniquely AIX commands you should have at your fingertips for the most common administrative tasks. Learn them, remember them, use them. 
1. smit: System Management Interface Tool
If you don't know about smit, you're truly an AIX neophyte. No shame in that, as long as you spend a goodly number of hours exploring and learning the smit menu structure (Figure 1, at bottom), which provides guided navigation to virtually every AIX command:
You can append a command name to smit (e.g., smit chuser), and smit walks you through each argument of the command, providing help text as well as lists of possible values. When you don't know what you're looking for or aren't even sure what you want to do, smit can help you peruse the AIX command structure until something strikes your fancy. 
2. prtconf: Print Configuration
You can't properly administer a machine if you don't know what AIX version and hardware components it's running. Every Unix platform seems to have its own private command to perform this task; with AIX it's prtconf. If you run prtconf without any options, it displays the values shown in Figure 2.
But prtconf doesn't stop there. It also displays several more pages of useful values: network addresses, paging space utilization, volume group usage, and a detailed inventory of installed hardware components (e.g., IDE, PCI, and SCSI storage adapters; Ethernet NICs; RAID controllers). You can supply option flags to extract a specific value, such as CPU type (-c), kernel address type (-k), or system memory capacity (-m), which can be very useful in scripts. The output is in the form of a key:value pair, which is easy to parse in a script:
# prtconf -k
Kernel Type: 64-bit

Other AIX-specific commands that provide similar information, but sometimes with more detail, includelsattrlscfgoslevel, and uname. Check out their man pages for details on their abilities. 
3. lsdev: List Attached Devices and Their Characteristics
Sometimes you just want to examine system peripherals by type, to determine whether you have an available unused device for a particular mission. The lsdev command delivers what you want, concisely and quickly. For example, to get a list of network interface cards, run
# lsdev -Cc if

and you get the output that Figure 3 shows. The -Cc option is an AIX idiom. The uppercase C indicates that you want to list a device identified in AIX's standardized Customized Devices object class; the lowercase c indicates that you will specify a single device class name, in this case "if" for network interfaces. Other common class name values include disk and tape. To list all the devices in the Customized Devices object class, just run lsdev -C. The command has loads of other options, which you can peruse in the man page. Be aware, however, that Linux has a command by the same name that operates completely differently.
4. lsuser: List User Attributes
User administration is another one of those functions that every Unix flavor seems to do differently, which makes privilege-sensitive scripts hard to write. For example, you would like to ensure that the user running a backup script is a member of the group with access to the tape drive. Usually you're forced to go mucking around in the /etc/passwd and /etc/group files for this information. AIX is better than most in this respect; its lsuser command lets you query the attributes of an individual user, and AIX by default stores more than 50 attributes, including a user's groups, home directory, shell, quotas, and last-login timestamps. For instance, you can run the command that Figure 4 shows and get output like that shown in the figure.
The -f option requests attributes in stanza form, indented under the user name, one attribute per line. Without -f, all the attributes are strung together on one line, which may be more convenient for parsing using regular expressions. Specifying ALL for the user name lists all user attributes for all users, or if you specify an attribute using the -a option, all of that attribute for all users, as Figure 5 demonstrates.
5. entstat: Display Ethernet Statistics
Many server performance problems can be traced back to bad network connectivity: defective cables, port speed/duplex mismatch, MTU failures, and so on. Other Unix flavors present this information in tabular form, which makes it difficult to query and parse easily. AIX's entstat tool delivers the stats for one interface at a time, with crystal-clear captions, making it easy to assess an interface's error conditions. The most common idiom for entstat is the one that Figure 6 depicts.
Every significant error counter includes the tag Error, so a simple grep for that string gives you a quick way to see if a particular network interface might be the cause of performance troubles. A related command idiom to see the port speed/duplex settings on an interface is this one:
# entstat -d en0 | grep "Media Speed"
Media Speed Selected: Auto negotiation
Media Speed Running: 100 Mbps Half Duplex

Note that AIX native Gigabit Ethernet controllers should always be configured to run in auto-negotiation mode, which you can enforce by using the following command:
# chdev -P -l ent2 -a \
     media_speed=Auto_Negotiation

6. svmon: System Virtual Memory Monitor
Troubleshooting application performance problems typically requires first verifying that resource starvation isn't the cause, and the most common resource that applications run out of is memory. Memory comes in two varieties, virtual and real, and despite the "v" in the svmon command name, it can report on real memory usage as well as virtual. For example, to discover the top three users of real memory, check out the command and output that Figure 7 shows. To get the same information for virtual memory, run svmon -Pgt 3
7. iptrace: TCP/IP Packet Capture Utility
The legendary packet-sniffing program popular on other Unix flavors, tcpdump, is available in AIX but may not be the best tool for the job. AIX's built-in iptrace utility collects more information than tcpdump, and its companion ipreport tool provides better decoding. Note, however, that iptraceactually runs as a daemon process in the background, rather than as a shell command in the foreground, as with tcpdump. Although you can invoke iptrace directly from the command line, it's easier to control if you use the Start System Resource (startsrc) and Stop System Resource (stopsrc) commands, as Figure 8 shows. You can then print out the captured packets, decoded, by usingipreport, as you see in Figure 9. As an added bonus, the trace.out file created by iptrace is readable by Windows-based network analyzers, such as the free Wireshark (wireshark.org).
8. topas: Top Resource Usage Monitor
Legacy Unix gave us the top command, a continuously updating list of the top CPU users on the system. AIX's topas is top on steroids. As you see in Figure 10, you get a CPU usage bar graph display (in hash marks), a list of top CPU consumers, network and disk I/O data rates, and a slew of other statistics critical for performance tuning.
The variant topas -E displays just the Ethernet throughput statistics. Alas, AIX doesn't have the good old original top command, but if you miss its columnar output, you'll be glad to know that topas -Pgives you almost the same thing.
9. mksysb: Make a Bootable System Backup
Creating a "bare metal" backup copy of an AIX installation is critical for rapidly recovering from a permanent system or hard drive failure. A "bare metal" backup is one you can restore to a completely new AIX server without the time-consuming manual task of reinstalling AIX from scratch, along with all the licensed program products and PTFs from the failed machine. The command is easy to use: Just provide the -i option and specify the device path for the backup device (in this case Removable Tape 0):
# mksysb -i /dev/rmt0

The mksysb command creates a "bare metal" backup by creating a binary image copy of the root volume group (rootvg), which is where the AIX operating system resides. You can use this copy to restore AIX to that point in time on repaired or new hardware. Even open files are backed up withmksysb
mksysb backup has three parts: a boot image, a complete list of files contained in the backup (image.data), and the actual binary image file. After mksysb writes these parts to the backup media, it compares what's on the list to what's on the tape in the backup as a verification step. If you create the backup on tape or UDFS-capable (DVD-ROM) media, the backup is bootable and includes the installation programs needed to install from the backup. If the tape drive to which you make the copy doesn't support bootable media, you need AIX licensed product DVDs or CDs to boot the system, and then you can restore the mksysb backup by using the restore command:
# restore -xqvf /dev/rmt0 /<code style="color: #006699; font-weight: bold;">restoremount point>

Although mksysb backs up the complete AIX operating system, it doesn't back up data in other volume groups, such as your application files. Traditional Unix uses the tar (Tape Archive) utility to do this, but AIX has a better way, the Save Volume Group (savevg) command:
# savevg -f /dev/rmt0 <code style="color: #006699; font-weight: bold;">volume group name>

Using savevg is better than using tar because savevg stores the logical volume sizes and mount names, so that they're automatically re-created when you restore the data by using the restvgcommand:
# restvg -f /dev/rmt0 <code style="color: #006699; font-weight: bold;">destinationdisk name>

As with mksysbsavevg can back up even open files, although you should take care with this feature because it may result in data backup being in an inconsistent state with respect to the underlying applications.
10. IBM's AIX Error Identifier Demystifier
This last "command" is not really a command, but it needs to be in your command-line toolkit anyway: the AIX Error Identifier Lookup web query page:
AIX has an extremely fine-grained error-coding scheme, which lets you get more information about the root cause of, and remedies for, any error ID returned from any command. This tool retrieves IBM's original error code specification sheet.

No comments:

Post a Comment