Tech Blog

These are blog entries written by the UNIX Health Check development team. Our team has extensive technical experience on both AIX and Red Hat systems, and we like to share our knowledge with our visitors.

Topics: AIX, System Admin

Calculating dates in Korn Shell

Let's say you wish to calculate with dates within a Korn Shell script, for example "current date minus 7 days". How do you do it? There's a tiny C program that can do this for you, called ctimed. You can download it here: ctimed.tar.

Executable ctimed uses the UNIX Epoch time to calculate. UNIX counts the number of seconds passed since Januari 1, 1970, 00:00.

So, how many seconds have passed since 1970?

# current=`./ctimed now`
This should give you a number well over 1 billion.

How many seconds is 1 week? (7 days, 24 hours a day, 60 minutes an hour, 60 seconds an hour):
# let week=7*24*60*60
# let aweekago="$current-$week" Convert this into human readable format:
# ./ctimed $aweekago
You should get something like: Sat Sep 17 13:50:26 2005

Topics: AIX, Performance, System Admin

Keeping a processor busy

There are times that you would like to create some "load" on the system. A very, very easy way of keeping a processor very busy is:

# yes > /dev/null
The yes command will continiously echo "yes" to /dev/null. This is a single-threaded process, so it will put load on a single processor. If you wish to put load on multiple processors, why not run yes a couple of times?

Topics: AIX, Monitoring, System Admin

Cec Monitor

To monitor all lpars within 1 frame, use:

# topas -C

Topics: AIX, Networking, ODM

AIX: Delete multiple default gateways

An AIX system should have a single default gateway defined. However, sometimes, it does occur that a system has multiple default gateways. Here's information to detect multiple default gateways and how to get rid of them:

First, obtain how many gateways there are:

# odmget -q "attribute=route" CuAt

CuAt:
        name = "inet0"
        attribute = "route"
        value = "net,-hopcount,0,,0,192.168.0.1"
        type = "R"
        generic = "DU"
        rep = "s"
        nls_index = 0

CuAt:
        name = "inet0"
        attribute = "route"
        value = "net,-hopcount,0,,0,192.168.0.2"
        type = "R"
        generic = "DU"
        rep = "s"
        nls_index = 0
If there are more than one, you need to remove the excess route. For example, to remove the default route to 192.168.0.2:
# chdev -l inet0 -a delroute="net,-hopcount,0,,0,192.168.0.2"
Method error (/usr/lib/methods/chginet):
        0514-068 Cause not known.
0821-279 writing to routing socket: The process does not exist.
route: not in table or multiple matches
0821-207 chginet: Cannot add route record to CuAt.
Then verify again:
# odmget -q "attribute=route" CuAt

CuAt:
        name = "inet0"
        attribute = "route"
        value = "net,-hopcount,0,,0,192.168.0.1"
        type = "R"
        generic = "DU"
        rep = "s"
        nls_index = 0

Topics: AIX, System Admin

Processor speed and more system information

To quickly show you the processor speed, cpu type, amount of memory and other system information, type:

# lsconf
You can also use prtconf.

Topics: AIX

Word wrapping files

If the lines in your text file are too long, you may want to word wrap them. In AIX this command is called fold:

# fold -sw 72 longfile > shortfile
This command will keep the longest line up to 72 characters and will not break a word in half. Without -w 72 lines will be wrapped to 80 characters.

Topics: AIX, Storage, System Admin

Using a DVD-RAM as a regular file system

To use a DVD-RAM for writing and reading like a file system, use the following commands. This will work only at AIX 5.2 and above:

  • Put a DVD-RAM into the drive
    # udfcreate -d /dev/cd0
  • Mount the DVD-RAM:
    # mount -V udfs /dev/cd0 /mnt
    If you get an error, ensure /etc/vfs contains this line (and retry the mount command after validating):
    udfs 34 /sbin/helpers/udfmnthelp
Then use this as a regular filesystem.

Topics: AIX, Backup & restore, System Admin

DVD-RAM Backup

You can use a DVD-RAM to create a system backup. To do so, enter:

# smitty mkdvd
This works in AIX 5.2 and above.

Topics: AIX, System Admin

Korn Shell history

To retrieve a list of all recent commands:

# history -100
This shows you the last 100 entries.

Topics: AIX, System Admin

Log file rotation script

A little script to rotate a log while not upsetting the process which is logging to the file. This script will copy and compress the log file, and then zero the log file out. Then the script will search for older log files and remove them after +3 days since last modification.

DATE=`date +%d%h-%I%p` 
BASE_DIR='/var' 
if [ -f $BASE_DIR/logname.log ]; then 
    cp $BASE_DIR/logname.log $BASE_DIR/logname.log.$DATE 
    > $BASE_DIR/logname.log 
    compress $BASE_DIR/logname.log.$DATE 
fi 

find $BASE_DIR -name 'logname.log.*' -a -mtime +3 -exec rm {} \; 

Number of results found for topic AIX: 231.
Displaying results: 161 - 170.