Bulk Remove AIX Print Queues

I have about 50 HP JetDirect print queues on an AIX system that I wanted to remove in a more automated way. The following KSH script is what I came up with to remove the device and queue.

The script attempts to ping the print queue (queues are added by DNS name). If the ping fails, I remove the device using rmqueudev and then remove the queue using rmque.

#!/bin/ksh

for i in $(lpstat | awk '{print $1}')
do

ping -c 1 -w 1 $i >/dev/null 2>&1


if [ $? -ge 1 ];
then
    echo "Purging $i"
    rmquedev -q $i -d hp@$i
    rmque -q $i
fi
done

After running this, I have 6 valid print queues that remain on the AIX system.

Get Process ID of an Established TCP Connection in AIX

There are numerous ways to accomplish getting the PID for an established network connection in AIX and Linux using tools like ss or more popular lsof.  In my situation, the system I was working on did not have ss or lsof, so I used netstat and rmsock.

If I know I have an established connection to a remote host 192.168.9.150, I can use netstat to narrow down and obtain the PCB/ADDR using the following command.

~ # netstat -naA|grep 192.168.9.150
f10000f3026fcb58 tcp4       0      0  10.147.204.10.40107 192.168.9.150.8010 ESTABLISHED

The first column of the netstat output is PCB/ADDR; using this value, I will use rmsock to identify the process.

~ # rmsock f10000f3026fcb58 tcpcb
The socket 0x26fc800 is being held by proccess 1302658 (x_ieswitch).

I can see the process ID (PID) is 1302658; to obtain more information, a simple ps command is executed.

~ # ps e 1302658
PID    TTY STAT  TIME COMMAND
1302658  pts/0 A     0:00 x_ieswitch p1_webxt_out 1 p1_webxt_out WEBXTOUT 5 _=

There are many ways to achieve what was done here as I had mentioned – such as using lsof, ss or even taking a look at some of the resources here: IBM DeveloperWorks Wiki

Test Dial on Modem in AIX

Had an issue with dialout on an AIX system this morning.  Problem resolved, but I learned a pretty handy little command for testing dial-out (I didn’t have a buttset with me).
Using cu -n -d -l tty2, I can dial-out to my cellphone to help in troubleshooting the problem.

# cu -n -d -l tty2
Please enter the number: xxxxxxxxxx
altconn called
Device Type ACU wanted
ttylock tty2 succeeded
Attempting to open /dev/tty2
clear O_NDELAY
filelock: ok
fixline(7, 19200)
gdial(fcmulhays) called
expect: ("")
got it
sendthem (DELAY
AT^M)
expect: (OK)
AT^M^M^JOKgot it
sendthem (PAUSE
nap(25) ATE1QV1M1Y1&R&D&E7#PDTxxxxxxxxxx^M)
expect: (CONNECT)
^M^JATE1QV1M1Y1&R&D&E7#PDTxxxxxxxxxx^M^Z[1] + Stopped (SIGTSTP)

Here we see it dial the number, my cellphone (indicated with X’s — creepers!).
This failed so I ^C the process. I reworked some of the terminations on the block from demarc and tried again. The next time was successful and I had received the dial-out call from AIX.