AIX Tip of the Week: UNIX "join" Command
Audience: AIX Users Date: December 1998
A little known, but useful, UNIX data manipulation tool is the join command. The function of the join command is si join. It combines common lines from two sorted text files based on a common field. The output of the join command remainder of each line from both files. Unmatched lines are not included in the output.
The following example illustrates the use of the join command. In this example, a hypothetical inventory file is joined on the part number. The inventory file is a two column file containing a list of part numbers and its quantity on hand. column file containing the part number and its description. The common field between the two files is the part numbe the part number.
Example
$ cat description.txt Part Number; Description 1; Pencils 2; Erasers 3; Paper Clips, Regular 3A; Paper Clips, Large 4; Paper, Regular 8.5x11 4A; Paper, Legal Size 5; Envelope 6; Staples 7; Tape 8; Hole Punch 9; Glue 10; Pen, Blue 10A; Pen, Red 10B; Pen, Black 10C; Pen, Green ....etc... $ cat inventory.txt Part Number; Quantity on Hand 1; 4 3; 16 3A; 24 4; 0 6; 1 8; 8 10; 2 10B; 14 ....etc.... $ join -t";" inventory.txt description.txt Part Number; Quantity on Hand; Description 1; 4; Pencil 3; 16; Paper Clips, Regular 3A; 24; Paper Clips, Large
4; 6; 8; 10; 10B; ....etc....
0; 1; 8; 2; 14;
Paper, Regular 8.5x11 Staples Hole Punch Pen, Blue Pen, Black
Note that only the matching lines are displayed. Unmatched lines are discarded. See the man page for the join comma
AIX Tip of the Week: Accesing Remote Tape Drives
Audience: AIX Users and Administrators Date: April 1999
One of the advantages of UNIX is the ability to share remote devices, such as tape drives. The "rdump/rrestore" comm backup/restore files to a tape drive on a remote system. However, because these commands require a ".rhost" file, ma security exposure.
One alternative is to use the more secure "rexec" command which prompts for a user id/password. The following exa "rexec" command to access remote tape drives. In this example, the "tape_host" is the TCP-IP hostname of the system "data_host" is the system where the files reside. The example also assumes you have a valid user id/password on both To create a backup to a remote system with a tape, issue the following command from the "data_host." tar -cvf - * | dd bs=1k | rexec tape_host "dd bs=1k of=/dev/rmt0" To restore this tape, issue the following command from the "tape_host" system. dd bs=1k if=/dev/rmt0 | rexec data_host "dd bs=1k | tar -xvf-" The general concept illustrated above can be extended to other remote devices such as diskettes, CD-ROMs and disk
AIX Tip of the Week: Using an RS/6000 System with a Graphics Display as an "X" Terminal
Audience: AIX Users Date: May 7, 1999
Any RS/6000 with a graphics terminal can be used as an "X" terminal**. An "X" terminal functions as a graphics dis a TCP/IP network. The following command starts a CDE session from a remote host on a local graphics display: X -query "remote_host_name"
Where "remote_host_name" is the TCP/IP name of the remote host. To run this command, you must be logged into th
display in the command line mode. The following keystroke combination terminates the session: Ctrl-Alt-Backspace
This command should work for any combination of UNIX systems that support X11 and XDM, including Sun, HP, IB
Comments:
1. Prerequisites: X11 and xdm software must be installed on both hosts. Both are included int the AIX base CDby default, but xdm may/may not be installed depending on the AIX. 2. My tests indicate that this command may fail on systems with multiple network adapters. Audience: AIX Administrators and End Users Date: November 12, 1999
Highlighting text on computer terminals is useful for drawing attention to important information. To highlight text on sessions, use the "tput" command. The types of highting available with "tput" includes blinking, bold, reverse, underl The attached "today" script uses the "tput" command to highlight today's date in the output of the "cal" command, as
July 1999 Sun Mon Tue Wed Thu 1 4 5 6 7 8 11 12 13 14 15 18 19 20 21 22 25 26 27 28 29 Fri 2 9 16 23 30 Sat 3 10 17 24 31
** Depends on the terminal's capability. Some ASCII terminals/emulators don't support all of the tput options. Refer more information.
#!/usr/bin/ksh # Script Name: today # v1.0 Calendar with today's date highlighted # Bruce Spencer, IBM # tput commands to control highlighting # note: some terminals do not support all tput options RVR=`tput smso` # reverse END_RVR=`tput rmso` # end reverse BLNK=`tput blink` # blink UNDER=`tput smul` # underline END_UNDER=`tput rmul` # underline CLEAR=`tput clear` # clear screen BELL=`tput bel` # bell sound BOLD=`tput bold` # bold DIM=`tput dim` # dim INVIS=`tput invis` # invisible
END=`tput sgr0` # Clear Screen echo ${CLEAR}
# turn off dim, blink, bold, dim, invisible
# Convert month abbreviation to month number set `date` case ${2} in Jan) MONTH=1;; Feb) MONTH=2;; Mar) MONTH=3;; Apr) MONTH=4;; May) MONTH=5;; Jun) MONTH=6;; Jul) MONTH=7;; Aug) MONTH=8;; Sep) MONTH=9;; Oct) MONTH=10;; Nov) MONTH=11;; Dec) MONTH=12;; *) MONTH=0;; esac DAY=`echo ${3} | sed "s/^0//"` cal $MONTH ${6} | sed "s/ ${DAY}/ ${RVR}${DAY}${END_RVR}/" # # # # # # # Examples of different formatting echo "${UNDER}Underline: Happy Thanksgiving!${END_UNDER}" echo "${BOLD}Bold: Happy Thanksgiving!${END}" echo "${DIM}Dim: Happy Thanksgiving!${END}" echo "${BELL}BELL: Happy Thanksgiving!${END}" echo "${INVIS}Invisible: Happy Thanksgiving!${END}" echo "${BLINK}Blink: Happy Thanksgiving!${END}"
Finding Files Containing a String
Audience: AIX Administrators Date: December 10, 1999 Here's a useful technique for searching for files in all subdirectories which contain a specific string. find . -type f -print | xargs -i grep -il "searchstring" {} where: "searchstring" is the desired search string "find . -type f -print" lists all files in the current directory and it subdirectories "xargs" feeds the file names from the pipe into the grep command at the curly braces {} The "grep -il" lists the files containing the "searchstring" (-i = case insensitive)
I use this command to find files on a web site that contain references to specific URL. Another variation would be to "searchstring" with another string by changing the "grep" to "sed" command. To save typing, put this command in a s
#!/usr/bin/ksh # Script name: locate find . -type f -print | xargs -i grep -il "$1" {}
To run, type locate searchstring, where searchstring" is the name of the search string.
Working with Diskettes in AIX
Audience: AIX Users Date: January 7, 2000 The following is a list of the most common commands for reading floppy diskettes in AIX.
Diskette Format PC DOS Command to View Diskette dosdir -l Comments
Part of the "bos.do
Related command dosformat Unix Unix Unix tar -tvf /dev/rfd0 restore -Tvq cpio -itv $results cmd2 >> $results : cmdN >> $results
Another way would be to use the Korn shell "grouping" syntax, which we could use to rewrite the above as:
( cmd1 cmd2 : cmdN ) > $results
The grouping technique has several advantages, including less typing, reduced I/O overhead (N file opens vs 1 file op
such as using a ">" that erases all the accumulated data in the file.
AIX Tip of the Week: Using AIX's "skulker" Command to Purge Unwanted Files
Audience: Systems Administrators Date: September 1, 2000
AIX's skulker command is a shell script that can be used to periodically purge obsolete or unneeded files. The skulke cron job during off-peak periods (uncomment the "skulker" line in root's crontab). You can modify skulker to suit loc information, see: http://www.rs6000.ibm.com/doc_link/en_US/a_doc_lib/cmds/aixcmds5/skulker.htm
AIX Tip of the Week: Using stty to Set Backspace Key
Audience: AIX Users Date: October 22, 2000 Sometimes when you telnet into a system,the backspace key produces output similar to: $ lss^[[2~^[[2~^[[2~ To fix, type: $ stty erase "BackspaceKey" The permanent solution is to edit your ".profile" and insert the following line: stty erase '^H'
AIX Tip of the Week: Using a Web Browser to FTP Files
Audience: AIX Users Date: November 25, 2000 Any web browser can be used to ftp files using the standard URL syntax: ftp://username:password@remote_host_name**
For security reasons, you should not include the password in the URL. The system will prompt for the missing passw -------
**Note: the full URL ftp syntax is ftp://username:password@remote_host_name:port/path;type=[a,d,i] Where port = the port number for ftp (if different from standard) path = the directory path, relative to the user id's home directory type = transfer type: a = ascii, d = directory listing, i = binary (default)
AIX Tip of the Week: Perl Trick to Edit Multiple Files with One Command
Audience: AIX Users Date: January 20, 2001
Here's a Perl trick that can simplify editing multiple files to make the same change. To illustrate, the following comm "LOTUS" to "IBM" in all files in the current directory. $ perl -p -i -e "s/LOTUS/IBM/g" * As with any global change command, be sure to back up the files before running the command.
Determining the Size of AIX Memory
Audience: Systems Administrators Date: February 16, 2001 This week's tip provides two useful commands for determining the size of AIX memory. For non root users, use the command: lsattr -El sys0 | grep realmem A simpler command for root users is: bootinfo -r
To determine what is occupying memory, use the svmon command. Only root can run the svmon command. For mor http://www.rs6000.ibm.com/doc_link/en_US/a_doc_lib/cmds/aixcmds5/svmon.htm http://www.rs6000.ibm.com/doc_link/en_US/a_doc_lib/aixbman/prftungd/2365c71.htm
Installing and Using AIX "man" Pages
Audience: Users Date: March 9, 2001 The "man" command provides online help for AIX commands. The most common form is man command
which lists the help page for "command". If you don't know the name of a command, or if you want to find related inf option: man -k searchstring
Man pages are not installed by default in AIX. The following filesets must be installed for man to work. The filesets a Documentation CD.
bos.html.en_US.topnav.navigate bos.html.en_US.nav bos.html.en_US.cmds.cmds1 bos.html.en_US.cmds.cmds2 bos.html.en_US.cmds.cmds3 bos.html.en_US.cmds.cmds4 bos.html.en_US.cmds.cmds5 bos.html.en_US.cmds.cmds6 Top Level Navigation Online Navigation AIX Commands Reference AIX Commands Reference AIX Commands Reference AIX Commands Reference AIX Commands Reference AIX Commands Reference
1 2 3 4 5 6
The following filesets are optional, for AIX system calls and C library functions, respectively.
bos.html.en_US.techref.base - AIX Base Tech Ref bos.html.en_US.techref.commo - AIX Commo Tech Ref
Using "infocmp" To Create Terminfo Files
Audience: Systems Administrators Date: June 14, 2001
When a telnet session does not correctly display full screen applications (like vi and smitty), the problem is usually ca definitions. The solution is to copy the "terminfo" file for the terminal to the remote server. If a terminfo file isn't ava the infocmp command. To illustrate, here's how you can create a LINUX terminal definition for AIX, which does not have one. On the Linux machine:
infocmp -I > linux.ti rcp linux.ti aixhost:/usr/lib/terminfo/linux.ti
rsh aixhost "tic /usr/lib/terminfo/linux.ti" telnet aixhost
The infocmp flag is an uppercase "i". The "aixhost" is the host name of the remote AIX system. This procedure shoul
ftp Checkpoint Restart
Audience: AIX Users Date: August 10, 2001
The AIX 4.3 ftp restart command allows you to resume an aborted file transfer at the point it stopped. This can be us over unstable connections because if the connection fails, you only have to transfer the remaining portion of the file.
The restart command did not work per the AIX documentation. Here's the procedure I tested. After an aborted file tr Log onto the remote host, and "cd" to the target directory. Then issue the commands: restart put Where is the size of the aborted file, in bytes.
The restart option is not 100% portable: I've successfully tested "restart" on AIX systems and between AIX/Linux sys Windows, and it does not appear to be an option in the Solaris documentation.
Listing the AIX System Configuration
Audience: All Date: January 30, 2002
You can use the prtconf command to list your AIX hardware configuration. including CPU's, memory, adapters, disk command is available the current version of AIX 4.3.3**, and on AIX 5. For those running older versions of AIX, he provide the same information.
General
prtconf lscfg [-v] lscfg -v lsdev -Cc adapter lsdev -Cc disk lsdev -Cc processor lsattr -El sys0 list system configuration devices (-v = verbose for microcode levels, etc) devices verbose (microcode level, firmware, etc) adapter cards disks - CPU's - serial number, model number, memory
AIX
oslevel instfix -i |grep ML - AIX OS level - AIX maintenance level
lslpp -l
- installed SW and levels
Disk
lsvg lsvg lsvg lslv lslv lspv lspv -o -p vgname -l vgname lvname -l lvname -l hdisk# active volume groups disk drives in VG LV's in VG LV detail LV disk location disks LV's residing on a disk
Network
lsdev -Cc if netstat -rn -List network interfaces -List network gateways
**If you can't upgrade to the current version of AIX, you can still download the prtconf tool from http://www.alphaw
64 Bit Commands
Audience: Administrators Date: February 9, 2002 Updated: 5/28/02 There are two common misconceptions about 64-bit applications. First, the 64 bit applications run faster. Second, 64 kernel.
64-bit applications improve performance when they can access more than 2 GB memory (a 32 bit limitation). Accessi magnitude faster than disk. Otherwise, 64 bit performance is comparable to a 32 bit application. Another misconception is that you need a 64 bit kernel to run a 64 bit applications. Both 32 and 64 bit kernels run 64 requires the 64 bit extensions. Here are a couple useful "64 bit" commands:
The bootinfo -y command tells whether the hardware is 32 or 64 bit enabled. Generally all hardware since the H70 is
The svmon -P <.pid #>. command lists whether a running application is 32 or 64 bit. It's listed under column the "64 output. (This command also shows whether the application is multithreaded under the "Mthrd" column.) The bootinfo -K shows whether the kernel is running 32/64 bit. This command only works for AIX 5 which can run (AIX 4 only runs a 32-bit kernel.) The administrator chooses which kernel at install time.
Another way to determine which kernel is running is the command: genkex | grep 64. You should see something like 149bf58 a3ec /usr/lib/drivers/syscalls64.ext
Determing the CPU Clock Speed
Audience: All Date: December 3, 2002 In AIX 5.1 pmcycles command lists the processor speed. The pmcycles command is part of the "bos.pmapi.pmsvcs"
If you have an AIX 4.3 system, the "uname -m" command provides a code that identifies the CPU. For more informa http://publib.boulder.ibm.com/doc_link/en_US/a_doc_lib/aixbman/prftungd/2365ax5.htm
Appendix D. Determining CPU Speed
With operating system versions later than 4.3.3, the pmcycles command (part of the perfagent.tools fileset) measure Performance Monitor counters. The speed is returned in Mhz. The pmcycles options are as follows: -m Run on all processors -d Print decrementer speed An example is as follows:
# pmcycles This machine runs at 451 MHz
If you are not on operating system version later than 4.3.3, there is no direct command to determine processor speed. uname command. Running the uname -m command produces output of the following form:
xxyyyyyymmss
where: xx 00 yyyyyy Unique CPU ID mm Model ID (the numbers to use to determine CPU speed) ss 00 (Submodel)
By cross-referencing the mm values from the uname -m output with the table below, you can determine the processor
Model ID 02 10 10 11 14 18 1C 20 2E 30 31 34 35 37 38 41 43 43 46 47 Machine Type 7015-930 7013-530 7016-730 7013-540 7013-540 7013-53H 7013-550 7015-930 7015-950 7013-520 7012-320 7013-52H 7012-32H 7012-340 7012-350 7011-220 7008-M20 7008-M2A 7011-250 7011-230 Processor Speed 25 25 25 30 30 33 41.6 25 41 20 20 25 25 33 41 33 33 33 66 45 Architecture Power Power Power Power Power Power Power Power Power Power Power Power Power Power Power RSC Power Power PowerPC RSC
48 4C 57 57 57 58 58 59 59 5C 63 63 64 64 66 67 67 70 70 71 72 72 72 75 75 75 76 76 77 77 77 79 79 80 81 89 89 94 94 A0 A1 A3 A4 A4 A4 A6 A7 C0 C0 C4 F0
7009-C10 7012-390 7030-3BT 9076-SP2 7012-380 7030-3AT 7012-39H 9076-SP2 7013-560 7015-970 7015-97B 7015-980 7015-98B 7013-580 7013-570 7015-R10 7013-590 9076-SP2 7013-58H 7013-59H 7015-R20 9076-SP2 7012-370 7012-375 9076-SP1 7012-360 7012-365 7012-350 7012-355 7013-55L 7013-591 9076-SP2 7015-990 7015-R24 7013-595 9076-SP2 7012-397 9076-SP2 7013-J30 7013-J40 7015-R30 7015-R40 7015-R50 9076-SP2 7012-G30 7012-G40 7024-E20 7024-E30 7025-F30 7007-N40
Thin
Thin w/L2
Wide
Wide Thin
Wide
Wide Thin
High
80 See Note 67 67 67 59 59 67 67 50 50 50 62.5 62.5 62.5 50 50 66 66 55 66 66 66 62 62 62 50 50 41 41 41.6 77 77 71.5 71.5 135 135 160 160 75 112 See Note See Note See Note See Note See Note See Note See Note See Note See Note 50
PowerPC 1. Power2 Power2 Power2 Power2 Power2 Power2 Power2 Power Power Power Power Power Power Power Power Power2 Power2 Power2 Power2 Power2 Power2 Power Power Power Power Power Power Power Power Power2 Power2 Power2 Power2 P2SC P2SC P2SC P2SC PowerPC PowerPC PowerPC PowerPC PowerPC PowerPC PowerPC PowerPC PowerPC PowerPC PowerPC ThinkPad
2. 2. 2. 2. 2. 2. 3. 3. 3.
Note 1
For systems where the uname -m command outputs a model ID of 4C; in general, the only way to determine machine with a model ID of 4C is to reboot into System Management Services and choose the system configu some cases, the information gained from the uname -M command can be helpful, as shown in the following t
uname -M IBM,7017-S70 Machine Type 7017-S70 Processor Speed 125 Processor Architecture RS64
IBM,7017-S7A 7017-S7A IBM,7017-S80 7017-S80 IBM,7025-F40 7025-F40 IBM,7025-F50 7025-F50 IBM,7026-H10 7026-H10 IBM,7026-H50 7026-H50 IBM,7026-H70 7026-H70 IBM,7042/7043 (ED) 7043-140 IBM,7042/7043 (ED) 7043-150 IBM,7042/7043 (ED) 7043-240 IBM,7043-260 7043-260 IBM,7248 7248-100 IBM,7248 7248-120 IBM,7248 7248-132 IBM,9076-270 9076-SP Silver Node
262 450 166/233 See Note 4. 166/233 See Note 4. 340 166/200/233/332 375 166/233 200 100 120 132 See Note 4.
RD64-II RS-III PowerPC PowerPC PowerPC PowerPC RS64-II PowerPC PowerPC PowerPC Power3 PowerPersonal PowerPersonal PowerPersonal PowerPC
Note 2:
# lscfg -vl cpucard0 | grep FRU FRU Number Processor Type Processor Speed E1D PowerPC 601 75 C1D PowerPC 601 75 C4D PowerPC 604 112 E4D PowerPC 604 112 X4D PowerPC 604e 200
For J-Series, R-Series, and G-Series systems, you can determine the processor speed in an MCA SMP system CPU card by using the following command:
Note 3: For the E-series and F-30 systems use the following command to determine CPU speed:
# lscfg -vp | pg
Look for the following stanza:
procF0 CPU Card
Part Number.................093H5280 EC Level....................00E76527 Serial Number...............17700008 FRU Number..................093H2431 Displayable Message.........CPU Card Device Specific.(PL)........ Device Specific.(ZA)........PS=166,PB=066,PCI=033,NP=001,CL=02,PBH Z=64467000,PM=2.5,L2=1024 Device Specific.(RM)........10031997 140951 VIC97276 ROS Level and ID............03071997 135048
In the section Device Specific.(ZA), the section PS= is the processor speed expressed in MHz. Note 4:
# lscfg -vp | more
For F-50 and H-50 systems and SP Silver Node, the following commands can be used to determine the proces Look for the following stanza:
Orca M5 CPU: Part Number.................08L1010 EC Level....................E78405 Serial Number...............L209034579
FRU Number..................93H8945 Manufacture ID..............IBM980 Version.....................RS6K Displayable Message.........OrcaM5 CPU DD1.3 Product Specific.(ZC).......PS=0013c9eb00,PB=0009e4f580,SB=0004f27 ac0,NP=02,PF=461,PV=05,KV=01,CL=1
In the line containing Product Specific.(ZC), the entry PS= is the processor speed in hexadecimal notation. speed, use the following conversions:
0009E4F580 = 166 MHz 0013C9EB00 = 332 MHz
The value PF= indicates the processor configuration.
251 261 451 461 = = = = 1 2 1 2 way way way way 166 166 332 332 MHz MHz MHz MHz
Using the "date" Command to Determine the Last Day of the Month
Audience: All Date: October 31, 2003 Updated: November 9, 2003
Determining the last day of a month in a shell script can be complicated because each month has a different number o year. Here's a trick with the "date" command that simplifies this calculation. I use it to archive rotating monthly logs, reports.
#!/usr/bin/ksh # Pacific Time: TZ=-16 (see below for explanation) if [ `TZ=-16 date +%d` = "01" ]; then # Run these commands ... fi
The timezone setting (TZ) setting tricks the date command into thinking it is 24 hours ahead. The syntax is counter in means forward, and a "+" sign means backward. Second, "TZ" is relative to GMT time. To illustrate, here are a few e ahead one day: GMT: TZ=-24 EST: TZ=-19 CST: TZ=-18 PST: TZ=-16 This trick can be used to calculate yesterday, tomorrow or two weeks from now.
Subject: Is There an AIX "unerase" Command?
Audience: Administrators Date: April 26, 2004
Unfortunately, there is no "unerase" command in Unix. The best alternative is to restore from a backup (You are mak As a last resort, you can try a data recovery tool, such as the one at http://www.compunix.com
(For others, search the web for "aix data recovery".) However, don't depend on these tools to recover data. None guar A better strategy is prevention. My suggestions are 1. 2. 3. 4. Never work as root for non administration tasks. Work as a regular user id Alias the "rm" command as "rm -i". Copy files before editing Make regular backups