Subject: AIX Frequently Asked Questions (Part 5 of 5)
Date: 04 Mar 1996 16:06:37 GMT
Summary: This posting contains AIX Frequently Asked Questions
         and their answers.  AIX is IBM's version of Unix.

Version: 5.02

= AIX FAQ Separator =======================================================

8.01: What hardware do I have?  What is available?  WITS?
From: C.Deignan@frec.bull.fr (C.DEIGNAN)
[ formerly in section 1.005 ]

#!/bin/ksh
#
#  wits - What Is The System
#       A shell script that gives information about the RS6000 or DPX/20
#       that it is being executed on.
#
# informations from : man uname (AIX4.1.2)
#                     Bull DPX/20 Reference Guide (rev. 6)
# lines with '#' haven't been verified
# Still don't know: 25W, C20, 40P
#
# Rev: 1.3.1
# Send comments and new info to C.Deignan@frec.bull.fr
# Thanks to:
#.Pete Forman (pete.forman@bedford.waii.com)
#.Dominique Trouette (for massive updating and the -l option)
#.+ The original author (identity lost)
#
##################################################################

#  Basic Concept: All AIX machines display a machine-specific
#                 number when uname -a is executed. This number is
#                 called the "machine ID". 2 digits of the machine ID
#                 allow the type of the machine to be identified.
#
# result of `uname -m` :
# 12 digits machine id: xxyyyyyymmss
# where :       xx      system = 00
#       yyyyyy  cpu id
#       mm      model id
#       ss      submodel number = 00


USAGE="wits - What Is The System
WITS looks at the uname of the machine to determine the model,
then displays \"catalogue\" info (CPU Speed, SPECint and SPECfp ratings,
etc), then uses standard AIX commands to give a quick summary of the hardware
on the machine.
Usage : $0 [-l] [-t ID] [-c]
Options : -l  choose from a list of Bull models
          -t  report on a particular two digit code
          -c  clear screen before reporting"

typeset -u MODNUM
MODNUM=""
doclear=""

#
#  Use getopt to analyse commands
#
set -- `getopt lt:c $*`
if [ $? != 0 ]
then
        echo "$USAGE"
        exit 1
fi


choosebull()
{
clear
print
print "Model Number\t   Model ID\t|\tModel Number\t   Model ID"
print "\t\t\t\t|\t\t\t\t"
print "DPX/20 ESTRELLA\t\tE0\t|"
print "\t\t\t\t|\t\t\t\t"
print "DPX/20 100/130\t\t47\t|\tDPX/20 100/150\t\t46"
print "DPX/20 200/215\t\t42\t|"
print "\t\t\t\t|\t\t\t\t"
print "DPX/20 300/310\t\t48\t|"
print "\t\t\t\t|\t\t\t\t"
print "DPX/20 400/470\t\t75\t|\tDPX/20 400/480\t\t58"
print "DPX/20 400/490\t\t57\t|\tDPX/20 400/490H\t\t59"
print "\t\t\t\t|\t\t\t\t"
print "DPX/20 600/640\t\t67\t|\tDPX/20 600/680\t\t71"
print "DPX/20 600/690\t\t70\t|\tDPX/20 600/690H\t\t72"
print "\t\t\t\t|\t\t\t\t"
print "DPX/20 800/890H\t\t82\t|"
print "\t\t\t\t|\t\t\t\t"
print "DPX/20 ESCALA D201-D401\tA0\t|"
print "DPX/20 ESCALA R201-R401\tA3\t|"
print "DPX/20 ESCALA M101-M401\tA6\t|"
print "\nWhich Model ID do you want ?\t\c"
read MODNUM
if [ "$MODNUM" = "" ]
then
.echo "no number, exiting"
.exit
fi
}



#
# input parameters control
#
for i in $*
do
.case $i in
.-l).choosebull; shift;;
.-t).MODNUM=$2; shift 2;;
.-c).doclear="true"; shift;;
.esac
done


if [ "$MODNUM" = "" ]
then
.MACHIDNUM=`uname -m`
.CPUNUM=`echo $MACHIDNUM | cut -c3-8`
.MODNUM=`echo $MACHIDNUM | cut -c9-10`
fi


if [ -n "$doclear" ] 
then tput clear; fi

processor=""
processor_num=""
clock_mhz=""
dcache_kB=""
icache_kB=""
L1cache_kB=""
L2cache_MB=""
mflops=""
specmarks=""
specint92=""
specfp92=""
bustech=""
busspeed_MBps=""
mem_MB=""
#memrate_MBps=""
other=""

case $MODNUM in

"10") BULLMODEL=""
IBMMODEL="IBM RISC System/6000 Model 7013-530 or 7016-730"
;;

"14") BULLMODEL=""
IBMMODEL="IBM RISC System/6000 Model 7013-540"
;;

"18") BULLMODEL="Bull DPX/20 Model 620"
IBMMODEL="IBM RISC System/6000 Model 7013-530H"
;;

"1C") BULLMODEL=""
IBMMODEL="IBM RISC System/6000 Model 7013-550"
;;

"20") BULLMODEL=""
IBMMODEL="IBM RISC System/6000 Model 7015-930"
;;

"2E") BULLMODEL=""
IBMMODEL="IBM RISC System/6000 Model 7015-950 or 7015-950E"
;;

"30") BULLMODEL=""
IBMMODEL="IBM RISC System/6000 Model 7013-520"
;;

"31") BULLMODEL=""
IBMMODEL="IBM RISC System/6000 Model 7012-320"
;;

"34") BULLMODEL="Bull DPX/20 Model 610"
IBMMODEL="IBM RISC System/6000 Model 7013-520H"
;;

"35") BULLMODEL="Bull DPX/20 Model 430"
IBMMODEL="IBM RISC System/6000 Model 7012-320H or 320E"
;;

"37") BULLMODEL="Bull DPX/20 Model 420"
IBMMODEL="IBM RISC System/6000 Model 7012-340 or 34H"
processor="Power"
clock_mhz="42"
dcache_kB="32"
icache_kB="32"
L2cache_MB="No"
specint92="48.1"
specfp92="83.3"
bustech="1 Microchannel (MCA) Bus"
busspeed_MBps="80"
mem_MB="from 16 to 512"
;;

"38") BULLMODEL="Bull DPX/20 Model 450"
IBMMODEL="IBM RISC System/6000 Model 7012-350"
;;

"41") BULLMODEL="Bull DPX/20 Model 115,125,125W,130S,135,135G,140,140S"
IBMMODEL="IBM RISC System/6000 Model 7011-22W,22W,22W+,230S,22G,22G,220,220+"
;;

"42") BULLMODEL="Bull DPX/20 Model 215 or 225"
IBMMODEL="IBM RISC System/6000 Model 7006-41W or 41T"
processor="PowerPC"
clock_mhz="80"
L1cache_kB="32"
L2cache_MB="0 or 0.5"
specint92="78.8/88.1"
specfp92="90.4/98.7"
mem_MB="from 16 to 256"
;;

"43") BULLMODEL="Bull DPX/20 Model 105"
IBMMODEL="IBM RISC System/6000 Model 7008-M20"
;;

"45") BULLMODEL="Bull DPX/20 Model 110"
IBMMODEL="IBM RISC System/6000 Model 7011-230, 23S or 23W"
;;

"46") BULLMODEL="Bull DPX/20 Model 150"
IBMMODEL="IBM RISC System/6000 Model 7011-250"
processor="PowerPC-601"
clock_mhz="66/80"
L1cache_kB="32"
L2cache_MB="No"
specint92="62.6/78.8"
specfp92="72.2/90.4"
bustech="1 Microchannel (MCA) Bus"
busspeed_MBps="80"
mem_MB="from 16 to 256"
;;

"46") BULLMODEL=""
IBMMODEL="IBM RISC System/6000 Model 7011-250"
;;

"47") BULLMODEL="Bull DPX/20 Model 130"
IBMMODEL="IBM RISC System/6000 Model 7011-230"
processor="Power"
clock_mhz="45"
dcache_kB="8"
L2cache_MB="No"
specint92="28.5"
specfp92="39.9"
bustech="1 Microchannel (MCA) Bus"
busspeed_MBps="40"
mem_MB="from 16 to 64"
;;

"48") BULLMODEL="Bull DPX/20 Model 310"
IBMMODEL="IBM RISC System/6000 Model 7009-C10"
processor="PowerPC-601"
clock_mhz="80"
dcache_kB="32"
L2cache_MB="0 or 1"
specint92="78.8/90.5"
specfp92="90.4/100.8"
bustech="1 Microchannel (MCA) Bus"
busspeed_MBps="80"
mem_MB="from 16 to 256"
;;

"4C") BULLMODEL=""
IBMMODEL="IBM RISC System/6000 Model 43P"
processor="PowerPC-604"
clock_mhz="100/120/133"
L2cache_MB="1/4 or 1/2"
specint92="128.1/157.9/176.4"
specfp92="120.2/139.2/156.5"
bustech="1 PCI Bus"
mem_MB="from 16 to 192"
busspeed_MBps="132 (unconfirmed)"
other="1 ISA Bus at 16 MB/s\n512MB Disk Space"
;;

"57") BULLMODEL="Bull DPX/20 Model 485 or 490"
IBMMODEL="IBM RISC System/6000 Model 7032-3AT or 7011-390"
processor="Power2-L2"
clock_mhz="67"
dcache_kB="64"
icache_kB="32"
L2cache_MB="0, 0.5, or 1"
specint92="109.7/113.2/114.3"
specfp92="202.1/204.5/205.3"
bustech="1 Microchannel (MCA) Bus"
busspeed_MBps="80"
mem_MB="from 32 to 512"
;;

"58") BULLMODEL="Bull DPX/20 Model 480 or 495"
IBMMODEL="IBM RISC System/6000 Model 7012-380 or 7030-3BT"
processor="Power2 or Power2-L2"
clock_mhz="59 or 67"
dcache_kB="64"
icache_kB="32"
L2cache_MB="No"
specint92="99.3 or 109.7"
specfp92="187.2"
bustech="1 Microchannel (MCA) Bus"
busspeed_MBps="80"
mem_MB="from 32 to 512"
;;

"59") BULLMODEL="Bull DPX/20 Model 490H"
IBMMODEL="IBM RISC System/6000 Model 3CT or 39H"
processor="Power2-L2"
clock_mhz="67"
dcache_kB="128"
icache_kB="32"
L2cache_MB="0, 1, or 2"
specint92="122.2/129.1/130.2"
specfp92="244.6/260.7/266.6"
bustech="1 Microchannel (MCA) Bus"
busspeed_MBps="80"
mem_MB="from 64 to 512"
;;

"5C") BULLMODEL="Bull DPX/20 Model 650"
IBMMODEL="IBM RISC System/6000 Model 7013-560"
;;

"63") BULLMODEL="Bull DPX/20 Model 810 or 820"
IBMMODEL="IBM RISC System/6000 Model 7015-97B or 970"
processor="Power"
clock_mhz="50"
dcache_kB="64"
icache_kB="32"
L2cache_MB="No"
specint92="58.8"
specfp92="108.9"
bustech="2 Microchannel (MCA) Buses"
busspeed_MBps="80"
mem_MB=" from 128 to 2048"
;;

"64") BULLMODEL="Bull DPX/20 Model 830 or 840"
IBMMODEL="IBM RISC System/6000 Model 7015-980 or 98B"
processor="Power"
clock_mhz="62.5"
dcache_kB="64"
icache_kB="32"
L2cache_MB="No"
specint92="73.3"
specfp92="134.6"
bustech="2 Microchannel (MCA) Buses"
busspeed_MBps="80"
mem_MB="from 128 to 2048"
;;

"66") BULLMODEL="Bull DPX/20 Model 660"
IBMMODEL="IBM RISC System/6000 Model 7013-580 or 58F"
processor="Power"
clock_mhz="62.5"
dcache_kB="64"
icache_kB="32"
L2cache_MB="No"
specint92="73.3"
specfp92="134.6"
bustech="1 Microchannel (MCA) Bus"
busspeed_MBps="80"
mem_MB="from 64 to 2048"
;;

"67") BULLMODEL="Bull DPX/20 Model 640"
IBMMODEL="IBM RISC System/6000 Model 7013-570"
processor="Power"
clock_mhz="50"
dcache_kB="32"
icache_kB="32"
L2cache_MB="No"
specint92="57.5"
specfp92="99.2"
bustech="1 Microchannel (MCA) Bus"
busspeed_MBps="80"
mem_MB="from 32 to 1024"
;;

"70"|"79") BULLMODEL="Bull DPX/20 Model 690"
IBMMODEL="IBM RISC System/6000 Model 7013-590"
processor="Power2"
clock_mhz="66.7"
dcache_kB="256"
icache_kB="32"
L2cache_MB="No"
specint92="121.4"
specfp92="254.2"
bustech="1 Microchannel (MCA) Bus"
busspeed_MBps="80"
mem_MB="from 64 to 2048"
;;

"71") BULLMODEL="Bull DPX/20 Model 680"
IBMMODEL="IBM RISC System/6000 Model 7013-58H"
processor="Power2"
clock_mhz="55.5"
dcache_kB="256"
icache_kB="32"
L2cache_MB="No"
specint92="97.6"
specfp92="203.9"
bustech="1 Microchannel (MCA) Bus"
busspeed_MBps="80"
mem_MB="from 64 to 2048"
;;

"72") BULLMODEL="Bull DPX/20 Model 690H"
IBMMODEL="IBM RISC System/6000 Model 7013-59H/R12"
processor="Power2"
clock_mhz="66.7"
dcache_kB="128"
icache_kB="32"
L2cache_MB="1"
specint92="124.4"
specfp92="250.7"
bustech="1 Microchannel (MCA) Bus"
busspeed_MBps="80"
mem_MB="from 64 to 2048"
;;

"75") BULLMODEL="Bull DPX/20 Model 470 or 475"
IBMMODEL="IBM RISC System/6000 Model 7012-370, 37T or 375"
processor="Power"
clock_mhz="62 or 62.5"
dcache_kB="32"
icache_kB="32"
L2cache_MB="No"
specint92="70.3"
specfp92="121.1"
bustech="1 Microchannel (MCA) Bus"
busspeed_MBps="80"
mem_MB="from 32 to 512"
;;

"76") BULLMODEL="Bull DPX/20 Model 460 or 465"
IBMMODEL="IBM RISC System/6000 Model 7012-360, 36T or 365"
processor="Power"
clock_mhz="50"
dcache_kB="32"
icache_kB="32"
L2cache_MB="No"
specint92="57.5 or 45"
specfp92="99.2 or 89"
bustech="1 Microchannel (MCA) Bus"
busspeed_MBps="80"
mem_MB="from 16 to 512"
;;

"77") BULLMODEL="Bull DPX/20 Model 455 or 630"
IBMMODEL="IBM RISC System/6000 Model 7012-350, 355 or 550L"
processor="Power"
clock_mhz="42"
dcache_kB="32"
icache_kB="32"
L2cache_MB="No"
specint92="48.1"
specfp92="83.3"
bustech="1 Microchannel (MCA) Bus"
busspeed_MBps="80"
mem_MB="from 32 to 256"
;;

"78") BULLMODEL=""
IBMMODEL="IBM RISC System/6000 Model 7012-315 or 7013-510"
;;

"80") BULLMODEL="Bull DPX/20 Model 890"
IBMMODEL="IBM RISC System/6000 Model 7015-990"
processor="Power2"
clock_mhz="71.5"
dcache_kB="256"
icache_kB="32"
L2cache_MB="No"
specint92="131"
specfp92="279"
bustech="2 Microchannel (MCA) Buses"
busspeed_MBps="80"
mem_MB="from 128 to 2048"
;;

"82") BULLMODEL="Bull DPX/20 Model 890H"
IBMMODEL="IBM RISC System/6000 Model R00 or R24"
processor="Power2-L2"
clock_mhz="71.5"
dcache_kB="128"
icache_kB="32"
L2cache_MB="2"
specint92="131.5"
specfp92="273.8"
bustech="2 Microchannel (MCA) Buses"
busspeed_MBps="2x80"
mem_MB="from 128 to 2048"
;;

"A0") BULLMODEL="Bull DPX/20 ESCALA Model D201 or D401"
IBMMODEL="IBM RISC System/6000 Model J30"
processor="PowerPC-601"
processor_num="2, 4, 6 or 8"
clock_mhz="75"
L1cache_kB="32"
L2cache_MB="1"
specint92="85 (per processor)"
specfp92="90.9 (per processor)"
bustech="1 to 2 (D201) or 2 (D401) Microchannel (MCA) Buses"
busspeed_MBps="160 or 2x160"
mem_MB="from 64 to 2048 (D201) or 256 to 2048 (D401)"
;;

"A3") BULLMODEL="Bull DPX/20 ESCALA Model R201"
IBMMODEL="IBM RISC System/6000 Model R30"
processor="PowerPC-601"
processor_num="2, 4, 6 or 8"
clock_mhz="75"
L1cache_kB="32"
L2cache_MB="1"
specint92="85 (per processor)"
specfp92="90.9 (per processor)"
bustech="2 Microchannel (MCA) Buses"
busspeed_MBps="2x160"
mem_MB="from 64 to 2048"
;;

"A6") BULLMODEL="Bull DPX/20 ESCALA Model M101 or M201"
IBMMODEL="IBM RISC System/6000 Model G30"
processor="PowerPC-601"
processor_num="1, 2 or 4"
clock_mhz="75"
L1cache_kB="32"
L2cache_MB="0.5"
specint92="80.3 (per processor)"
specfp92="85.3 (per processor)"
bustech="1 Microchannel (MCA) Bus"
busspeed_MBps="160"
mem_MB="from 32 to 512 (M101) or 64 to 512 (M201)"
;;

"E0") BULLMODEL="Bull DPX/20 ESTRELLA Model DT603 or MT603"
#  IBMMODEL=""
processor="PowerPC-604"
clock_mhz="100"
L1cache_kB="16"
L2cache_MB="1/4"
specint92="60.6"
specfp92="60.7"
mem_MB="from 16 to 128 (M101) or 32 to 128 (M201)"
bustech="1 PCI Bus"
busspeed_MBps="132"
other="1 ISA Bus at 16 MB/s\nOn-Board Graphic Adapter with 1-2MB DRAM"
;;

*) BULLMODEL="Hey! I don't know this machine ID ($MODNUM)!!
Please send a mail to C.Deignan@frec.bull.fr and describe it to me. Thanks."
;;

esac

#
# Results screen
#
echo "----------------------------------------\c"
echo "--------------------------------------"
echo "\t${BULLMODEL}\n\t${IBMMODEL}"

if [ -n "${processor}" ]
then
.echo "----------------------------------------\c"
.echo "--------------------------------------"
.echo "\t\tCatalogue Reference Information\n"

.if [ -n "${processor_num}" ];
..then echo "${processor_num} ${processor} CPUs\c"
..else echo "${processor} CPU\c"
..fi

.if [ -n "${clock_mhz}" ]; then echo " at ${clock_mhz} MHz\c" ; fi
.echo  ""

.if [ -n "${dcache_kB}" ];
..then echo "\tdata cache : ${dcache_kB} KBytes" ; fi
.if [ -n "${icache_kB}" ];
..then echo "\tinstruction cache : ${icache_kB} KBytes"; fi
.if [ -n "${L1cache_kB}" ];
..then echo "\tL1 cache : ${L1cache_kB} KBytes per CPU"; fi
.if [ -n "${L2cache_MB}" ];
..then echo "\tL2 cache : ${L2cache_MB} MByte per CPU" ; fi
.if [ -n "${mem_MB}" ]; then echo "memory : ${mem_MB} MB"; fi
.if [ -n "${bustech}" ]
.then
..echo "${bustech}\c"
..if  [ -n "${busspeed_MBps}" ]
..then
...echo " at ${busspeed_MBps} MBytes/sec"
..fi
.fi
.if [ -n "${mflops}" ]; then echo "MFLOPS : ${mflops}" ; fi
.if [ -n "${specmarks}" ];
..then echo "SPECmarks : ${specmarks}" ; fi
.if [ -n "${specint92}" ];
..then echo "SPECint92 : ${specint92}" ; fi
.if [ -n "${specfp92}" ];
..then echo "SPECfp92 : ${specfp92}" ; fi
.echo

.if [ -n "${other}" ]; then echo "${other}"; fi
fi

echo "----------------------------------------\c"
echo "--------------------------------------"

if [ -n "$CPUNUM" ]
then
.typeset -i count_cpu
.LANG=En_US...# same as LANG=C for AIX 4.1
.exec 2>/dev/null
.print "\t\tCurrent Configuration Information\n"
.echo "Hardware ID :  $CPUNUM\tModel ID :  $MODNUM \c"
.count_cpu=$(lscfg -l "proc*" 2>/dev/null | tail -n +3 | wc -l)
.if [ $count_cpu -gt 1 ]
.then
..echo "($count_cpu Processors)"
.else
..echo "(Mono-Processor)"
.fi

# Add up the memory space available. Uses awk, a bit messy, but solid.
.echo "$(lscfg -l "mem*" | awk '/MB/ {res += $3}
END { print res}') MB RAM"

# Awk script to display disk space. uses "lsvg rootvg"
.lsvg $(lsvg) | awk -v "tot=0; fre=0" '
/TOTAL PP/ { sub( ".*TOTAL PP.*\\(", ""); tot += $1}
/FREE PP/ { sub( ".*FREE PP.*\\(", ""); fre += $1}
END  { printf( "%d MB Total Disk Space Available, %d MB Unallocated\n",
..tot, fre)}'

.lscfg -l "bus*" | tail -n +3 | cut -c39-70
.lscfg -l "rmt*" | tail -n +3 | cut -c39-79
.lscfg -l "cd*" 2>/dev/null | tail -n +3 | cut -c39-79
.echo ""
.echo "----------------------------------------\c"
.echo "--------------------------------------"
fi

echo

= AIX FAQ Seperator =======================================================

8.02: Cleaning up utmp, who, and accounting problems
[ formerly in section 1.103 ]

#include <sys/types.h>
#include <utmp.h>
#include <fcntl.h>

main ()
{
.int.fd;
.struct.utmp.utmp;

.while (1) {
..if ((fd = open ("/etc/utmp", O_RDWR)) < 0)
...exit (1);

..while (read (fd, &utmp, sizeof utmp) == sizeof utmp) {
...if (utmp.ut_type == USER_PROCESS &&
.....kill (utmp.ut_pid, 0) != 0) {
....lseek (fd, - (long) sizeof utmp, 1);
....utmp.ut_type = DEAD_PROCESS;
....write (fd, &utmp, sizeof utmp);
...}
..}
..close (fd);
..sleep (60);
.}
}

= AIX FAQ Seperator =======================================================

8.03: How do I set up postscript accounting?
[ formerly in section 1.118 ]

/*  pswrap.c

 compile with:   cc pswrap.c -o pswrap -lqb
 (for doc on the qb library see "understanding backend routines in libqb")

 BTW:  The log_charge() function doesn't seem to do anything,
       but log_pages() updates the accounting info.

Ephraim Vider, original author 

--
Feb 10, 1993

You can set pswrap up to use either the accounting file specified in
/etc/qconfig (which means that you need to get your data from 'pac') or
you can comment out the #define WANT_PAC line and then the accounting
data will only go into the ACCTFILE.

Also modified the logging to the ASCII acctfile so that it looks more
readable.

Vince Taluskie
*/

 #include <stdio.h>
 #include <string.h>
 #include <ctype.h>
 #include <fcntl.h>
 #include <signal.h>
 #include <setjmp.h>
 #include <sys/wait.h>
 #include <IN/backend.h>
 #include <IN/standard.h>
 #include "qprocs.h"
 
 char     *nextword (char *p);
 char     *skipvalue (char *p);
 
 #define LOGDIR     "/tmp"
 #define ACCTFILE   "/usr/adm/acct/lpr/ps-acct"
/* #define WANT_PAC .1 */     /* this define will also send accounting
                                 info to the acctfile specified in
.... /etc/qconfig file.  If this define is 
.... commented out then accounting info will
.... only go to ACCTFILE  */
 

 char     pcprog[] = "statusdict begin pagecount = end\n\x04";
 
 char     *keyw[] = {
     "idle",
     "busy",
     "waiting",
     "printing",
     "initializing",
     NULL
 };
 enum     { PS_IDLE, PS_BUSY, PS_WAIT, PS_PRINT, PS_INIT, PS_UNKNOWN };
 
 void     giveup();
 jmp_buf  jumper;
 
 char     logfname[30];
 FILE     *logfile, *acctfile;
 
 main (argc, argv)
 int argc;
 char     *argv[];
 {
     char *devname;
     int  pagcnt, c;
     int  pid;
     int  w, status;
 
     if (argc < 2) {
          fprintf(stderr, "Usage: psbe file\n");
          exit(-1);
     }
     if (log_init(argv[1]) < 0) {
          fprintf(stderr, "log_init failed!\n");
          exit(EXITBAD);
     }
     sprintf(logfname, "%s/%s.log", LOGDIR, get_device_name());
     if ((logfile = fopen(logfname, "a")) == NULL) {
          fprintf(stderr, "Can't open logfile.\n");
          exit(EXITBAD);
     }

     if ((acctfile = fopen(ACCTFILE, "a")) == NULL) {
. fprintf(stderr, "Can't open logfile.\n");
. exit(EXITBAD);
. }

     setvbuf(logfile, NULL, _IOLBF, BUFSIZ);
     setvbuf(acctfile, NULL, _IOLBF, BUFSIZ);

     setvbuf(stdin, NULL, _IONBF, 0);
     setvbuf(stdout, NULL, _IONBF, 0);
     fprintf(logfile, "start Job no. %d, queued on %s\n", get_job_number(),
               get_qdate());
     log_status(WAITING);
     pagcnt = getpagecnt();
     log_status(RUNNING);
     if ((pid = fork()) < 0) {
          perror("fork");
          exit(EXITBAD);
     }
     if (pid == 0) {
          argv[0] = "piobe";
          execv("/usr/lpd/piobe", argv);
          perror("exec");
          exit(EXITBAD);
     }
     while ((w = wait(&status)) != pid)
          if (w == -1) {
               perror("wait");
               exit(EXITBAD);
          }
     if (WEXITSTATUS(status) != 0)
          exit(WEXITSTATUS(status));
     log_status(WAITING);

     if (pagcnt > 0 && (c = getpagecnt()) > 0) {
#ifdef WANT_PAC 
          log_pages(c - pagcnt);
#endif
.}

     fprintf(logfile, "end Job no. %d, queued on %s\n", get_job_number(),
               get_qdate());

/* the accounting file format is 

pages_printed     user     queue_printed_on   time_queued

*/

     fprintf(acctfile, "%d %35s %7s    %s \n", (c - pagcnt), get_from(), get_queue_name(), get_qdate());

     fclose(logfile);
     fclose(acctfile);
     exit(EXITOK);
 }
 
 void     giveup ()
 {
     longjmp(jumper, 1);
 }
 
 getpagecnt ()
 {
     int  pc = 0, pstat;
     char buf[81];
 
     if (setjmp(jumper) != 0) {
          fprintf(logfile, "giving up on status\n");
          return (0);
     }
     alarm(60 * 2);
     signal(SIGALRM, giveup);
     do {
          if (!gets(buf)) {
               sleep(5);
               putchar('\x14');    /* ^T returns status */
               sleep(1); /* wait for answer from printer */
               if (!gets(buf))
                    return (0);
          }
          fprintf(logfile, "%s\n", buf);
          if ((pstat = getstatus(buf)) == PS_WAIT) {
               putchar('\x04');
               sleep(1);
          }
     } while (pstat != PS_IDLE);
     alarm(0);
     while (gets(buf))
          fprintf(logfile, "%s\n", buf);
     printf("%s", pcprog);
     sleep(1); /* wait for answer from printer */
     if (!gets(buf))
          return (0);
     if (sscanf(buf, "%d", &pc) != 1)
          return (0);
     fprintf(logfile, "%d\n", pc);
     return (pc);
 }
 
 /*
  * Parser for printer status messages
  */
 
 getstatus (p)
 char     *p;
 {
     char *t;
     int  i;
 
     if ((p = strchr(p, '%')) == NULL)
          return (PS_UNKNOWN);
     if (strncmp(p, "%%[", 3) != 0)
          return (PS_UNKNOWN);
     for (p = nextword(p + 3) ; p != NULL ; p = skipvalue(p)) {
          t = p;
          p = strchr(p, ':');
          *p++ = '\0';
          p = nextword(p);
          if (strcmp(t, "status") == 0)
               break;
     }
     if (p == NULL)
          return (PS_UNKNOWN);
     t = p;
     p = strchr(p, ' ');
     if (p[-1] == ';')
          p--;
     *p = '\0';
     for (i = 0 ; keyw[i] != NULL ; i++)
          if (strcmp(t, keyw[i]) == 0)
               break;
     return (i);
 }
 
 char     *nextword (p)
 char     *p;
 {
     while (isspace(*p))
          p++;
     if (strncmp(p, "]%%", 3) == 0)
          return (NULL);
     return (p);
 }
 
 char     *skipvalue (p)
 char     *p;
 {
     char *t;
 
     while (p != NULL) {
          p = strchr(p, ' ');
          t = p;
          p = nextword(p);
          if (t[-1] == ';')
               break;
     }
     return (p);
 }

 /*********    qprocs.h    ***********/
 /* functions for communication between qdaemon and the backend */
 
 char     *get_from();
 char     *get_to();
 char     *get_qdate();
 char     *get_queue_name();
 char     *get_device_name();
 char     *get_title();


= AIX FAQ Seperator =======================================================

8.04: How can I find out the machine type?
From: umar@compsci.cas.vanderbilt.edu (Sait Umar)
[ formerly in section 1.126 ]

#!/bin/sh
#
#  Author G. Vitillaro              (peppe@ipgaix.unipg.it)
#  from an idea of Marc Pawliger    (marc@ibmpa.awdpa.ibm.com)
#
#  10/12/92  GVT  First (and last) implementation
#  2/21/95   posted by hjiwa@nor.chevron.com (Jeff Wang)
# machine : will get machine type on RISC/6000
#
#

awk '
  BEGIN {
    m["10"]="7013/530 or 7016/730";
    m["11"]="7013/540";
    m["14"]="7013/540";
    m["18"]="7013/530H";
    m["1C"]="7013/550";
    m["20"]="7015/930";
    m["2E"]="7015/950";
    m["2E"]="7015/950E";
    m["30"]="7013/520";
    m["31"]="7012/320";
    m["34"]="7013/520H";
    m["35"]="7012/320H or 320E";
    m["37"]="7012/340
    m["38"]="7012/350";
    m["41"]="7011/220";
    m["43"]="7008/M20";
    m["45"]="7011/M20";
    m["48"]="7009/C10";
    m["5C"]="7013/560";
    m["57"]="7012/390 or 7030/3BT";
    m["63"]="7015/970";
    m["64"]="7015/980";
    m["66"]="7015/580";
    m["67"]="7015/570";
    m["70"]="7013/590";
    m["71"]="7013/58H";
    m["75"]="7012/370, 375, or 37T";
    m["76"]="7012/360, 365, or 36T";
    m["77"]="7012/350, 355, or 7013/550L";
    m["78"]="7012/315 or 7013/510 ";
    m["80"]="7015/990";
    m["82"]="7015/R24";
    if ( m[code] != "" )
      print "This RISC/6000 is a " m[code];
    else
      print "Unknown Machine";
  }
' code=`uname -m | cut -c9-10` < /dev/null


= AIX FAQ Seperator =======================================================

8.05: Updating to 3.2.5
[ formerly in section 1.127 ]

=-=-=-=-=-=-=-= cut here =-=-=-=-=-=-=-=-=-=-=
#!/bin/ksh
# @(#) mktape2disk.sh  creates files from tape on disk.

# change name prefix here
NAME="f"

# from file #i to file #j
integer i=1
integer j

# test arguments
if [ -z "${1}" ]
then
  echo "\nusage: $(basename ${0}) <drive_no> <#files>\n"
  echo "\t<drive_no>: tape drive number (e.g. 0)"
  echo "\t<#files>  : number of files to copy from the tape\n"
  exit 1
fi
device=/dev/rmt${1}.1

# test arguments
if [ -z "${2}" ]
then
  echo "\nusage: $(basename ${0}) <drive_no> <#files>\n"
  echo "\t<drive_no>: tape drive number (e.g. 0)"
  echo "\t<#files>  : number of files to copy from the tape\n"
  exit 1
fi
j=${2}

tctl -f ${device} rewind
if [ $? -ne 0 ]
then
  exit 1
fi

# create tape
while [ ${i} -le ${j} ]
do
    echo "Copy file #${i} of #${j} from (${device}) to disk as (${NAME}${i})."
    dd if=${device} of="${NAME}${i}" bs=200k
    i=i+1
done
tctl -f ${device} rewind
exit 0
=-=-=-=-=-=-=-= cut here =-=-=-=-=-=-=-=-=-=-=

5) Create a new .toc file

   # cd /pub/pmp3250
   # inutoc .
   # pg .toc

6) Place the following file named 'runme.sh' in the PMP directory

=-=-=-=-=-=-=-= cut here =-=-=-=-=-=-=-=-=-=-=
#!/bin/ksh
# @(#) runme.sh for PMP3250
#
INSTP="/usr/sbin/installp"
LOG="/tmp/installp.log"
TEE="/usr/bin/tee"
PATCHDIR=$(pwd)
#
/usr/bin/cp /usr/lpp/info/data/ispaths /usr/lpp/info/data/ispaths.save
#
INFODIR="/usr/lpp/info/$LANG/aixmin"
/usr/bin/mkdir ${INFODIR} 2>/dev/null >/dev/null
if [ ! -w ${INFODIR} ]
then
    print "\n\t*ERROR* Can not (write) access [${INFODIR}]."
    print "\tPlease unmount CD or NFS filesystems.\n"
    exit -1
fi
#
# Commit all ptf's
#
${INSTP} -Xc all 2>&1 | ${TEE} ${LOG}.0
#
# Install latest installp patch
#
${INSTP} -BXacgq -d ${PATCHDIR} bos.obj 3.2.0.0.U422463 2>&1 | ${TEE} ${LOG}.1
#
# Install latest installp patch
#
${INSTP} -BXacgq -d ${PATCHDIR} bos.obj 3.2.0.0.U422467 2>&1 | ${TEE} ${LOG}.6
#
# Run the ptfdir clean utility.
#
/usr/sbin/ptfdir_clean -y -f -v 2>&1 | ${TEE} ${LOG}.2
#
# Install the PMP.    Version 1
#
/usr/lib/instl/sm_inst installp_cmd   \
        -T m -q -a -g -B              \
        -d ${PATCHDIR}                \
        -S '3250 AIX Maintenance Level U493250' \
        -c  -N  -X                    \
        2>&1 | ${TEE} ${LOG}.3
#
# Install the PMP.    Version 2
#
# /usr/sbin/update_all
#
# Install latest installp patch
#
/usr/bin/lppchk -v | ${TEE} ${LOG}.4
#
# Show level of installp patch
#
/usr/bin/lslpp -m bos.obj | ${TEE} ${LOG}.5
#
# Guess you should reboot now.
#
sync;sync
print - "\n\n\tDone......guess you should reboot now !!\n"
exit 0
=-=-=-=-=-=-=-= cut here =-=-=-=-=-=-=-=-=-=-=

7) To run the update on your server

   ===>> Please read the Installation Instructions first <<==

   # cd /pub/pmp3250
   # ./runme.sh

                   ........WAIT...........

   # /etc/shutdown -Fr

8) NFS export the PMP dir as READ-ONLY to all your clients.

9) To update a client system

    a -  Mount the PMP filesystem from the server
    b -  cd <mounted_filesystem>
    c -  execute ./runme.sh
    d -  Unmount PMP filesystem
    e -  reboot

10) To create a copy 1:1 of the tape you received use the script 'mktape.sh'

   # cd /pub/pmp3250
   # mktape.sh 0

=-=-=-=-=-=-=-= cut here =-=-=-=-=-=-=-=-=-=-=
#!/bin/ksh
# @(#) mktape.sh: creates a bootable tape from images on disk

# change name prefix here
NAME="f"

# usage: mktape drive_no
#        drive_no = tape drive number
# test arguments
if [ -z "${1}" ]
then
  echo "\nusage: mktape <drive_no>"
  echo "         <drive_no>: tape drive number (e.g. 0)\n"
  exit 1
fi
device=/dev/rmt${1}.1

tctl -f ${device} rewind
if [ $? -ne 0 ]
then
  exit 1
fi

# create tape
i=1
while test -r "${NAME}${i}"
do
    echo "copy ${i}"
    if [ $i -le 3 ]
    then
      dd if="${NAME}${i}" of=${device} conv=sync bs=1k
    else
      dd if="${NAME}${i}" of=${device} bs=200k
    fi
    let i=${i}+1
done
tctl -f ${device} rewind
exit 0


= AIX FAQ Seperator =======================================================

8.06: How do I do remote backup?
[ formerly in section 1.201 ]

From: kraemerf@franvm3.VNET.IBM.COM (Frank Kraemer)
#!/bin/ksh
# @(#) Create a backup tape of the private user data.
#=================================================================#
#   Script :  usave.sh                                            #
#   Author :  F. Kraemer                                          #
#   Date   :  92/02/19                                            #
#   Update :  92/10/29                                            #
#   Info   :  the ultimative backup script                        #
#   Example:  usave.sh /dev/rmt0      -  save to local tape       #
#             usave.sh /save/save.me  -  save to local file       #
#             usave.sh /tmp/pipe      -  save to remote tape      #
#-----------------------------------------------------------------#
PS4="(+) "
#set -x
PROG=$(basename $0)
HOST=$(hostname)
TODAY=$(date +%H:%M:%S)
#
# cleanup
#
cleanup ()
{
ec=$1
error=$2
case "$ec"
in
   "$USAGE_EC")    # usage error
     error="Usage:\t$PROG DeviceName\n" 1>&2
    ;;
   "$NOTAP_EC")    # Tape error
     error="error:\t$PROG: $DEVICE is not available on the system.\n" 1>&2
    ;;
   "$LISTE_EC")    # list error
     error="error:\t$PROG: could not create tar list for $LOGNAME.\n" 1>&2
    ;;
   "$NOTAR_EC")    # tar command error
     error="error:\t$PROG: tar command failed.\n" 1>&2
    ;;
   "$PIPEP_EC")    # pipe error
     error="error:\t$PROG: mknod command failed.\n" 1>&2
    ;;
   "$NORSH_EC")    # rsh error
     error="error:\t$PROG: rsh - Remote Shell command failed.\n" 1>&2
    ;;
   "$RHOST_EC")    # remote host error
     error="error:\t$PROG: Remote Host unknown.\n" 1>&2
    ;;
   *)
   ;;
esac
case "$DEVICE"
in
    #
    # Fix the block size if $DEVICE is a tape device
    #
    /dev/rmt[0-9]*)
        echo "\n\t$PROG: Rewinding tape to begin.........(please wait)\n"
        tctl -f $DEVICE rewind 2>/dev/null
        ;;
    *) ;;
esac
rm -f ${LIST} ${PIPE} 2>/dev/null
[ -n "$error" ] && echo "\n${error}\n"
trap '' 0 1 2 15
exit "$ec"
}
#
# Variables
#
USAGE_EC=1                         # exit code for usage error
NOMNT_EC=2                         # exit code wrong device name
NOTAP_EC=3                         # exit code no tape available
LISTE_EC=4                         # exit code backup list error
NOTAR_EC=5                         # exit code for wrong tar
TRAPP_EC=6                         # exit code for trap
PIPEP_EC=7                         # exit code for pipe
RHOST_EC=8                         # exit code for bad ping
NORSH_EC=9                         # exit code for bad rsh
DEVICE="$1"                        # device to tar into
LIST="/tmp/.tar.$LOGNAME.$$"       #
REMOTEH=""                         # Remote host for backup
REMOTET=""                         # Remote tape for backup
tapedev=                           #
PIPE="/tmp/pipe"                   # Pipe for remote backup
#
# main()
#
tput clear
echo "\n\t$PROG started from $LOGNAME@$HOST on $TERM at $TODAY.\n"
rm -f $LIST 2>/dev/null
#
# Trap on exit/interrupt/break to clean up
#
trap "cleanup $TRAPP_EC \"Abnormal program termination. $PROG"\"  0 1 2 15
#
# Check command options
#
[ "$#" -ne 1 ]  &&  cleanup "$USAGE_EC" ""
#
# Check device name
#
[ `expr "$DEVICE" : "[/]"` -eq 0 ] && cleanup "$NOMNT_EC" \
        "$PROG: Backup device or file name must start with a '/'."
#
# Check tape device
#
case "$DEVICE"
in
    #
    # Fix the block size if $DEVICE is a tape device
    #
    /dev/rmt[0-9]*)
        #
        echo "\n\t$PROG: Verify backup media ($DEVICE)............\n"
        #
        # see if a low or high density tape device was specified
        # (eg rmt0.1)
        density="`expr $DEVICE : \
                "/dev/rmt[0-9]*\.\([0-9]*\)"`"
        #
        # strip /dev/ from device name and
        # get the base name (eg translate:
        # /dev/rmt0.2 to rmt0)
        #
        tapedev="`expr $DEVICE : \
                "/dev/\(rmt[0-9]*\)[\.]*[0-9]*"`"
        #
        # Check if the tape is defined in the system.
        lsdev -C -c tape -S Available -F "name" | grep $tapedev >/dev/null 2>&1
        rc=$?
        [ "$rc" -ne 0 ] && cleanup "$NOTAP_EC" ""
        #
        # Restore old tape name.
        #
        [ "${density:-1}" -lt 4 ] && density=1 || density=5
        DEVICE="/dev/${tapedev}.${density}"
        echo "\n\t$PROG: Insert a tape in ($DEVICE)........(press enter)\n"
        read TEMP
        echo "\n\t$PROG: Rewinding tape to begin...........(please wait)\n"
        tctl -f $DEVICE rewind 2>/dev/null
        ;;
    #
    # Backup is done on remote host. The remote shell facility
    # must be set up and running.
    #
    ${PIPE}*)
        #
        echo "\n\t$PROG: Assuming remote backup via network.\n"
        echo "\t$PROG: Enter name of Remote Host   ===> \c"
        read REMOTEH
        echo "\n\t$PROG: Pinging Remote Host to test connection.\n"
        ping ${REMOTEH} 1 1 >/dev/null 2>&1
        rc=$?                                    # give up unknown host
        [ "$rc" -ne 0 ] && cleanup "$RHOST_EC" ""
        JUNK=$(rsh ${REMOTEH} "/usr/sbin/lsdev -C -c tape -S Available")
        rc=$?                                    # give up rsh failed
        [ "$rc" -ne 0 ] && cleanup "$NORSH_EC" ""
        echo "\t$PROG: Available Tapes on ${REMOTEH} are :\n\n\t\t${JUNK}\n"
        echo "\t$PROG: Enter name of Remote Tape (e.g. /dev/rmt0) ===> \c"
        read REMOTET
        echo "\n\t$PROG: Insert tape on ${REMOTEH} in ${REMOTET}..(press enter)"
        read TEMP
        echo "\t$PROG: Rewinding Remote Tape ${REMOTET} on ${REMOTEH}.\n"
        rsh ${REMOTEH} "tctl -f ${REMOTET} rewind"
        rc=$?                                    # give up rsh failed
        [ "$rc" -ne 0 ] && cleanup "$NOTAP_EC" ""
        rm -f ${PIPE} 2>/dev/null
        mknod ${PIPE} p
        rc=$?                                    # give up mknod failed
        [ "$rc" -ne 0 ] && cleanup "$PIPEP_EC" ""
        cat ${DEVICE} | rsh ${REMOTEH} "dd of=${REMOTET} obs=100b 2>/dev/null" &
        ;;
    *)  ;;
esac
#
# Prepare the list
#
echo "\n\t$PROG: Create list of files to be saved...."
find $HOME -print > $LIST
rc=$?
[ "$rc" -ne 0 ] &&  cleanup "$LISTE_EC" ""
#
# tar the files
#
echo "\n\t$PROG: Changing current directory to (/)...."
cd / > /dev/null 2>&1
echo "\n\t$PROG: Running tar format backup from user ($LOGNAME)...."
tar -cvf "$DEVICE" -L "$LIST"
rc="$?"
[ "$rc" -ne 0 ]  && cleanup "$NOTAR_EC" ""
#
# Backup completed
#
TODAY=$(date +%H:%M:%S)
echo "\n\t$PROG ended at $TODAY............................\n\n"
cleanup 0


= AIX FAQ Seperator =======================================================

8.06: How do I do remote backup? (cont.)
From: Henk van Doorn <hvdoorn@xs4all.nl>

#!/bin/ksh
#######################################################################
#     rmksysb                                                         #
#######################################################################
#                                                                     #
# Description:                                                        #
#       creates a bootable mksysb backup of a remote system running   #
#.AIX 3.x or lists the Table of Contents of the current tape    #
#                                                                     #
# Usage:                                                              #
#       ./rmksysb $1 [$2] .....      #
#..$1 - remote host to be backed up..      #
#..$2 - optional: local tape device (default: rmt0)      #
#.or:.......      #.
#../rmksysb -l [$2]                                             #
#..to list Table of Contents saveset on tape in $2.      #
#..(only useful on tapes created by rmksysb).      #
#                                                                     #
# Output:                                                             #
#       a bootable mksysb of the remote system                        #
#.or a listing of the TOC saveset on the current tape.      #
#                                                                     #
# Remarks:.......      #
#.. rmksysb can only be used by root...      #.
#.. this script will use tapedevice .1, so if .  .      #
#.  a >2.3GB drive is used: check density_set_1.              #
#.. the remote host needs /.rhosts to include the local host    #
#.  for root access (+ shell enabled in /etc/inetd.conf)        #.
#.. you will need some room (>1.5MB) on /tmp on the remote host #
#.  for standard mksysb .archive.list.* etc...      #
#.. remote standard output & standard error (except dd/chdev)   #
#.  will go to local stdout & stderr...      #
#.. redirecting stdout can create quite large log-files (2MB)   #
#.. AIX versions should not be too far apart as the boot-saveset#
#.  comes from the local system & the rest from the remote      #
#.  (tested on AIX 3.2.5, AIX 4+ definitely won't work!!!)      #
#.. most likely this script will fail with multi-tape mksysb's: #
#.  another incentive to keep rootvg as small as possible!      #
#........      #
# Author:.......      #
#.Henk van Doorn......      #
#.Email: hvdoorn@xs4all.nl       ....      #
#........      #
#.Thanks to all who contributed. Esp. Paul Wynn (AIXpert '93),  #
#.my colleagues Dominic Dinardo & Douwe van Terwisga.      #
#.+ the input from Usenet were stimulating; thanks folks!.      #
#.I would welcome any additions & changes for the better...     # 
#                                                                     #
#######################################################################
#         CHANGES                                                     #
#######################################################################
#                                                                     #
# ID. WHO   DATE                        DESCR                      #
# --. ---   -------  --------------------------------------------- #
# X000. HvD   6Jan95   Created this file.                            #
# X001. HvD   2Feb95   Final version                                 #
#######################################################################

set +u

# Global variable definitions.
UMASK=`umask`
BLK_SZ=1024
BOOT_BLK_SZ=512
HOST=${1}

# TAPE = $2 with /dev/ & .* removed, defaulting to rmt0
TAPE=${2:-rmt0}
TAPE=${TAPE#/dev/}
TAPE=${TAPE%.*}

usage()
{
    echo "Usage: ./rmksysb <remote_host_name> [<tape_device>] or" >&2
    echo "       ./rmksysb -l [<tape_device>]" >&2
    echo "                 with <tape_device>= e.g. rmt1" >&2
    echo "Default <tape_device>=rmt0" >&2
    return
}

check_parms()
{
if [ "${HOST}" = "" ]
then
.usage
.exit 1
fi

if [ "${HOST}" = "-l" ]
then
# show TOC block which contains some backup details on rmksysb tapes
.get_tape_block_size
.chdev -l ${TAPE} -a block_size=${BOOT_BLK_SZ} >/dev/null 2>&1
.mt -f /dev/${TAPE} rewind
.mt -f /dev/${TAPE}.1 fsf 2
.dd if=/dev/${TAPE} count=1 2>/dev/null
.chdev -l ${TAPE} -a block_size=${OLD_BLK_SZ} >/dev/null 2>&1
.exit 
fi
}

check_host()
{
rsh ${HOST} hostname >/dev/null 2>&1
if [ $? -ne 0 ]
then
.echo "Check hostname & rsh access" >&2
.exit 1
fi
}

get_tape_block_size()
{
VALID=
`lsdev -Cc tape | cut -f1 -d" " | grep ${TAPE} 2>&1 >/dev/null` && 
.{
        OLD_BLK_SZ=`lsattr -El ${TAPE} -a block_size | cut -f2 -d" "`
        VALID=true
        }

if  [ "$VALID" = "" ]
then
.echo "Tape drive $TAPE is not a valid local drive!" >&2
.exit 1
fi
}

#
# The main procedure is analogous to its C counterpart,
# This is the basic driver routine.
#
main()
{

if [ "`id | grep 'uid=0'`" = "" ]
then 
.echo "rmksysb can only be run as root!" >&2
.exit 2 
fi
umask 022

check_parms
check_host
get_tape_block_size

# display some info on this rmksysb session
echo "`date`\n\nRemote System Backup from remote ${HOST} to local `hostname` on device:\n`lscfg -v -l ${TAPE} | sed -n '3,6p' | grep "[a-z]" `\n" 

# Here the action starts
rsh $HOST -n /usr/bin/mkszfile
rsh $HOST -n "echo ${BLK_SZ} > /tapeblksz"

rsh $HOST -n "rm -f /tmp/pipe.rmksysb"
rsh $HOST -n "rm -f /tmp/pipe.rmksysb.out"
rsh $HOST -n "rm -f /tmp/pipe.rmksysb.err"

rsh $HOST -n "/etc/mknod /tmp/pipe.rmksysb p"
rsh $HOST -n "/etc/mknod /tmp/pipe.rmksysb.out p"
rsh $HOST -n "/etc/mknod /tmp/pipe.rmksysb.err p"

# create remote startup file for mkinsttape
rsh $HOST -n "echo '#!/bin/ksh\nexport PATH=$PATH ; /usr/sbin/mkinsttape /tmp/pipe.rmksysb >/tmp/pipe.rmksysb.out 2>/tmp/pipe.rmksysb.err &' > /tmp/mkinsttape.start "
rsh $HOST -n "chmod 700 /tmp/mkinsttape.start"

chdev -l $TAPE -a block_size=${BOOT_BLK_SZ} >/dev/null 2>&1
tctl -f /dev/${TAPE} retension

echo
echo
echo ">>> SAVESET 1: BOS boot image from `hostname`"
echo
bosboot -d /dev/${TAPE}.1 -a 

echo
echo
echo ">>> SAVESET 2: BOS install utilities from ${HOST} (backup format)"
echo
rsh $HOST -n "nohup /tmp/mkinsttape.start" &

# get remote standard out & err to local stdout & err
rsh $HOST -n "dd if=/tmp/pipe.rmksysb.out 2>/dev/null" | dd 2>/dev/null &
rsh $HOST -n "dd if=/tmp/pipe.rmksysb.err 2>/dev/null" | ( dd 2>/dev/null ) >&2 &

# get remote mkinsttape to local tape device
rsh $HOST -n "dd if=/tmp/pipe.rmksysb 2>/dev/null" | dd 2>/dev/null | dd of=/dev/${TAPE}.1 conv=sync 2>/dev/null

echo
echo
echo ">>> SAVESET 3: Backup information (list with ./rmksysb -l [<tapedevice>])"
echo
# add dummy TOC to tape with some backup information
echo "`date`\n\nRemote System Backup from remote ${HOST} to local `hostname` on device:\n`lscfg -v -l ${TAPE} | sed -n '3,6p' | grep "[a-z]" `\n" | dd of=/dev/${TAPE}.1 conv=sync 2>/dev/null

# change blocksize to 1024 for better performance
chdev -l ${TAPE} -a block_size=${BLK_SZ} >/dev/null 2>&1

# rewind & skip first 3 savesets
mt -f /dev/${TAPE} rewind
mt -f /dev/${TAPE}.1 fsf 3

echo
echo
echo ">>> SAVESET 4: mksysb (rootvg backup) from ${HOST} (tar format)"
echo
# start the actual remote mksysb
echo "The contents of the /.fs.size file on ${HOST} are:"
rsh $HOST -n "cat /.fs.size"
echo

rsh $HOST -n "nohup /usr/bin/mksysb /tmp/pipe.rmksysb >/tmp/pipe.rmksysb.out 2>/tmp/pipe.rmksysb.err &" &

# get remote standard out & err to local stdout
rsh $HOST -n "dd if=/tmp/pipe.rmksysb.out 2>/dev/null" | dd 2>/dev/null &
rsh $HOST -n "dd if=/tmp/pipe.rmksysb.err 2>/dev/null" | ( dd 2>/dev/null ) >&2 &
 
# get remote mksysb to local tape device
rsh $HOST -n "dd if=/tmp/pipe.rmksysb 2>/dev/null" | dd obs=${BLK_SZ} 2>/dev/null | dd of=/dev/${TAPE} bs=${BLK_SZ} conv=sync 2>/dev/null

# cleaning up
rsh $HOST -n "rm -f /tmp/pipe.rmksysb"
rsh $HOST -n "rm -f /tmp/pipe.rmksysb.out"
rsh $HOST -n "rm -f /tmp/pipe.rmksysb.err"
rsh $HOST -n "rm -f /tmp/mkinsttape.start"

chdev -l ${TAPE} -a block_size=${OLD_BLK_SZ} >/dev/null 2>&1
umask $UMASK

# display some closing info on this rmksysb session
echo "Remote System Backup from remote ${HOST} to local `hostname` is finished.\n`date`\n" 

} #end of main

# Call the driver
main 


= AIX FAQ Seperator =======================================================

8.07*: How to configure dialup SLIP

[ formerly in section 1.606 part 5 ]

#!/bin/ksh

# SLIP login .profile
# Adapted from comp.unix.aix FAQ
# by Davide Migliavacca (davide.migliavacca@inferentia.it)
# $Revision: 2.8 $

# Set this variable != 0 to allow multiple logins from this userid

ALLOW_MULTIPLE_LOGINS=0

# NOTE: script currently determines destination IP address from the SLIP
# interface attributes, but it assumes a correspondence
#     ttyxx <-> slipxx
# (see the "IPADDRESS=" awk line)
# It relies on a client being able to read the IP address from
# the logon procedure output.


PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:$HOME/bin:/usr/bin/X11:/sbin:/usr/local/bin:.

export PATH ENV HISTSIZE
#
# Search for a LCK-File for our tty if there is one
#
TTYDEV=`tty`
TTYBASENAME=`basename $TTYDEV`
TTYNUMBER=`echo $TTYBASENAME | sed -n -e "s/tty\([0-9]\{1,\}\)/\1/p"`

if [ -f /etc/locks/LCK..$TTYBASENAME ];
then SHPID=`cat /etc/locks/LCK..$TTYBASENAME`;
else {
/usr/bin/logger -t SLIP -p error "No LCK file for $TTYDEV"
 exit 64;
}
fi;


# Search for another login from this userid

OTHERSLIP=`ps -fu$USER |
      sed -n -e "s/^ *$USER  *[0-9][0-9]* .*-.*\/usr\/sbin\/slattach \(tty[0-9]\{1,\}\) *$/\1/p`;
if [ ! -z "$OTHERSLIP" ];
then
   if [ $ALLOW_MULTIPLE_LOGINS -eq 0 ];
   then
           echo "Sorry, you are already connected to $OTHERSLIP.";
           echo "Multiple logins are NOT allowed.";
           echo "For any question, contact helpdesk@inferentia.it";
           /usr/bin/logger -t SLIP -p warn "$USER: attempt to connect on $TTYBASENAME when already connected on $OTHERSLIP - refused";
           exit 64;
   fi
#else...
   /usr/bin/logger -t SLIP -p warn "$USER: multiple login allowed, now using also $TTYBASENAME";
fi
#
# Search for our own Shell to get the PID for checking against LCK-File
#

SH2PID=`ps -ft$TTYNUMBER |
        sed -n -e "s/^ *$USER  *\([0-9][0-9]*\) .*-.*sh *$/\1/p`

#
# Is it the the same PID as in the LCK File so that we can start working ??
DEBUG=0
if [ $DEBUG -eq 1 ];
then
   echo TTYDEV: $TTYDEV
   echo TTYBASENAME: $TTYBASENAME
   echo USER: $USER
   echo SHPID: $SHPID
   echo SH2PID: $SH2PID
fi
if [ "$SHPID" -eq "$SH2PID" ];
then
#  remove the LCK-File because slattach does not like it.
   rm -rf /etc/locks/LCK..$TTYBASENAME
#  Add RTS/CTS Handshakeing to our own tty: Better do it in /etc/rc,
#  using the program from the comp.unix.aix FAQ.
#  stty add rts
   SLIPLINE=`echo $TTYBASENAME | awk '//{print substr($1,4);}'`
   IPADDRESS=`lsattr -E -l sl$SLIPLINE -a dest 2>/dev/null | awk '//{print $2;}'`
   if [ -z "$IPADDRESS" ]
   then
   /usr/bin/logger -t SLIP -p error "$USER: attempt to use tty with no slip interface defined ($TTYBASENAME)"
   echo "This tty ($TTYBASENAME) has not been enabled for SLIP. Please try another one or contact the system administrator."
   exit 64
   fi
   echo SLIP starting. Your IP address is $IPADDRESS
   /usr/sbin/slattach $TTYBASENAME
# Get the pid of slattach so that we can kill him later on.
   SLPID=`ps -aef |
      sed -n -e "s/^ *$USER  *\([0-9][0-9]*\) .*-.*\/usr\/sbin\/slattach $TTYBASENAME *$/\1/p`
#  Just say that we are up.
   logger -t SLIP -p info "$USER: Starting up daemon (pid $SLPID) for [$IPADDRESS] on $TTYDEV"
else
# Something must be wrong with the LCK-File
  SH3PID=`ps -aef | awk ' {print $2}' | grep $SHPID`

  if [ ."$SH3PID" = ."" ]
  then
    SH3PID="NO_SUCH_PROCESS"
  fi

  if [ $SHPID = $SH3PID ]
    then
#  There is a living process which owns the LCK-File !!
   /usr/bin/logger -t SLIP -p error "$USER: Cannot remove LCK file for $TTYDEV (not owner)"
       exit 64
    else
#   Who the hell didn't remove the LCK-File (should never happen)
   /usr/bin/logger -t SLIP -p error "$USER: LCK file for $TTYDEV found with no owner"
       #echo `date` " LCK-File with no owner found !!!" >>$SLIPLOG
       exit 64
    fi
fi

if [ $DEBUG -eq 1]
then
   /usr/bin/logger -t SLIP -p debug "$USER: going to trap signals..."
fi
Nov 28 11:18:46 sauternes rexecd[21420]: connect from brachetto.inferentia.it

                                                                             # terminated )
trap "kill $SLPID; /usr/bin/logger -t SLIP -p info \"$USER: Killing daemon (pid $SLPID) for $TTYDEV\"; exit 0" 1

if [ $DEBUG -eq 1]
then
   trap "/usr/bin/logger -t SLIP -p debug \"$USER: trap ERR\"" ERR
   trap "/usr/bin/logger -t SLIP -p debug \"$USER: trap 0\"" 0
   trap > /tmp/trap.$TTYBASENAME.log
   /usr/bin/logger -t SLIP -p debug "$USER: trap returns $?..."
fi

# We  will have a nice sleep and nice dreamings
if [ $DEBUG -eq 1]
then
   /usr/bin/logger -t SLIP -p debug "$USER: going to sleep-loop..."
fi

while [ true ];
do
sleep 60;
done

# Sanity check (should never happen...)
/usr/bin/logger -t SLIP -p error "$USER: ERROR: .profile broken"


= AIX FAQ Seperator =======================================================

8.08: Disabling software flow control; using RTS/CTS.

[ formerly in section 1.613 ]

/* This program is an adaptation of a program provided by IBM Defect Support.
   It is provided without warrantee, or support.

   The syntax of the command is:

.setrts tty [tty [tty [...]]]

   The program will loop through each tty provided on the command line, and 
   turn on the 'rts' line discipline.  The program does not require that
   the Carrier Detect signal be held high to keep the serial device from 
   blocking on the attempt to open it.  The program works for all valid ttys.

   BUGS: None that are known; however, using the program to set 'ptys' may
   cause the 'pty' to become unusable.

   This program was written by Robin D. Wilson, Pencom Software (with the
   specific 'ioctl()' call provided by the IBM Defect Support Center.

   I call it: "setrts"
   
   To compile:
   cc -O -o setrts setrts.c
   strip setrts
   
   (Funny, but if you strip with the compiler (i.e., cc -s), you end up with
   120 extra bytes in the executable...)
*/

#include <stdio.h>
#include <fcntl.h>
#include <termios.h>
#include <sys/tty.h>
#include <string.h>
#include <sys/param.h>
#include <unistd.h>

#define DEVDIR.."/dev/"
#define.LINEDISP."rts"

main (argc, argv)
int argc;
char **argv;
{
.int tty;
.char ttyname[MAXPATHLEN];

/*.Give a 'usage' recommendation if they don't provide an argument */
.if (argc < 2) {
.   fprintf(stderr, "usage: %s <ttyn> [ttyn [ttyn [...]]]\n",argv[0]);
.   exit(-1);
.}
 /*.Otherwise, loop through all the arguments... */
.else while (--argc >= 1) {
..argv++;
 /*.Check to see if they input the 'tty' names with the DEVDIR on them...
 *.If not, put it on...
 */
..if (strncmp(DEVDIR, argv[0], strlen(DEVDIR)) != 0) {
...strcpy(ttyname, DEVDIR);
...strcat(ttyname, argv[0]);
..}
..else
...strcpy(ttyname, argv[0]);

/*.Open the tty.  Use the non-blocking open (O_NDELAY) to open without a 
 *.carrier (CD) present on the line...
 */
..if ((tty = open(ttyname, O_RDWR|O_NDELAY)) < 0) {
..   fprintf(stderr, "%s: couldn't open tty device.\n",ttyname);
..   exit (-2);
..}
 /*.Add the 'rts' line discipline... */
..(void)ioctl(tty, TXADDCD, LINEDISP);
..(void)close(tty);
.}
}


= AIX FAQ Seperator =======================================================

*8.09: How can I hack libc.a to alter how hostnames are resolved?

[ formerly in section 1.618 ]

[ Editor's note: You might want to see Question 2.07 for advice on
recovering from a deleted or corrupted libc.a before attempting this
hack. ]

1. get the resolv+ source (I see a copy on ftp.uu.net in networking/ip/dns
   and there are likely copies elsewhere).  We are using version 2.1.1,
   which appears to be the latest available.  gethostnamadr.c needs a couple
   of additions:

.23a24,26
.> #ifdef _AIX
.> #include <sys/time.h>
.> #endif
.35a39,41
.> #ifdef _AIX
.> #include <sys/ioctl.h>         /* for SIOCGIFCONF */
.> #else
.36a43
.> #endif

2. Use the following instead of the supplied shlib/Makefile:

LIBP=.gethostnamadr.o herror.o res_data.o res_query.o res_mkquery.o \
.sethostent.o res_send.o res_debug.o res_comp.o res_init.o
CFLAGS=.-O -D_BSD=43 -D_NO_PROTO -DNIS -DDEBUG -U__STR__

all: shr.o 

shr.o:.$(LIBP) setup 
.ld -o $@ /lib/syscalls.exp $(LIBP) tmp.o -bM:SRE -bE:shr.exp -bE:/lib/syscalls.exp -bI:crypt.imp -H512 -T512 -bh:4 -lc

setup:
.rm -f libc.a crypt.imp
.cp /lib/libc.a .
.chmod 755 libc.a
.ar xv libc.a shr.o
./bin/dump -nv shr.o | grep EXP | awk '{print $$NF}' > shr.exp
.ld -o tmp.o -bnso shr.o -r
.@ echo '#!' > crypt.imp
.@ echo __crypt >> crypt.imp
.@ echo __setkey >> crypt.imp
.@ echo __encrypt >> crypt.imp
.
clean:
.rm -f shr.o tmp.o crypt.imp shr.exp $(LIBP) libc.a

install_libc:.install_libc.c
.cc -o $@ install_libc.c -bnso -bI:/lib/syscalls.exp

herror.o: ../herror.c
.$(CC) $(CFLAGS) -c ../herror.c

res_comp.o: ../res_comp.c
.$(CC) $(CFLAGS) -c ../res_comp.c

res_debug.o: ../res_debug.c
.$(CC) $(CFLAGS) -c ../res_debug.c

res_data.o: ../res_data.c
.$(CC) $(CFLAGS) -c ../res_data.c

res_init.o: ../res_init.c
.$(CC) $(CFLAGS) -c ../res_init.c

res_mkquery.o: ../res_mkquery.c
.$(CC) $(CFLAGS) -c ../res_mkquery.c

res_query.o: ../res_query.c
.$(CC) $(CFLAGS) -c ../res_query.c

res_send.o: ../res_send.c
.$(CC) $(CFLAGS) -c ../res_send.c

gethostnamadr.o: ../gethostnamadr.c
.$(CC) $(CFLAGS) -c ../gethostnamadr.c

sethostent.o: ../sethostent.c
.$(CC) $(CFLAGS) -c ../sethostent.c

strpbrk.o: ../strpbrk.c
.$(CC) $(CFLAGS) -c ../strpbrk.c

strerror.o: ../strerror.c
.$(CC) $(CFLAGS) -c ../strerror.c

3. As shipped, IBM's /lib/syscalls.exp contains an entry for fork().  This
   needs to be removed as it will cause the new shr.o to use the system call
   entry point rather than the library wrapper and this can cause some rather
   odd behavior.  For example, I ran across one using the '!' command in vi
   where the error/informational messages were corrupted.

4. You can use "ar r libc.a shr.o" but that will leave a big hole in libc.a,
   since the new shr.o is slightly bigger than the original.  I always extract
   all the .o's from libc.a and build a brand new one - suit yourself.

5. Before the next step, you'll want to set up the two configuration files.
   The first is /etc/resolv.conf and it is basically the same as before
   except for the new keyword "search" - intended to replace the "domain".  See
   the resolver.5 manual page for details (included with the resolv+ source).
   The other file is /etc/host.conf, which is where you set the order of
   search.  See resolv+.8 for information on this.

6. Now, the only tricky part left is to get the new libc.a installed.  You'll
   note the Makefile has a target for install_libc.  Just put the following
   in install_lib.c and run "make install_libc" to build.

------------------------------- begin install_libc.c -------------------------
#include <stdio.h>

static char *nodns[] = { "/usr/ccs/lib/libc.a" , "/usr/ccs/lib/libc.a.ORIG" };
static char *hasdns[] = { "/usr/ccs/lib/libc.a.NEW" , "/usr/ccs/lib/libc.a" };

#define OLD     (0)
#define NEW     (1)

main()
{

.if(link(nodns[OLD],nodns[NEW])) {
..perror("link");
..exit(1);
.}

.if(unlink(nodns[OLD])) {
..perror("unlink");
..exit(1);
.}

.if(link(hasdns[OLD],hasdns[NEW])) {
..perror("link");
..exit(1);
.}

.if(unlink(hasdns[OLD])) {
..perror("unlink");
..exit(1);
.}

.exit(0);
}
------------------------------- end install_libc.c ---------------------------

7. You'll want to do this on a quiet machine.  Move the new libc.a to
   /usr/ccs/lib/libc.a.NEW, then run install_libc.  It is probably a good
   idea to reboot afterwords (though not strictly required).  We have a similar
   program called restore_libc (exercise for the reader) for backing out the
   change.

   Rather than do this on every machine (we have 170+ RS/6000's), I simply
   put this new libc.a into my network-installable image, which I blasted
   out over the year-end holiday break (I created a method for loading a new
   image onto machines without having to boot off of floppies and turn keys).

   Of course, for the really cautious, you can always make the change after
   booting off of the maintenance floppies...


= AIX FAQ Seperator =======================================================

8.10: How do I make an export list from a library archive?

[ formerly in section 2.17 ]

This script will only extract the "export"able names and should be
useful in starting the shared library creation process. The user must
determine which names should be included in the import and export lists.
It's only been tested on a few library archives.

#!/bin/ksh
#
# mkexps - make export list
# This program creates an export list by combining all the "." and normal names
# into one list. 
#
if [[ "$#" -ne 1 ]]
then
    print "Usage: mkexps ArchiveFile"
    exit -2
fi
if [[ ! -f $1 ]] 
then
    print "mkexps: Cannot open file \"$1\""
    exit -1
fi
dump -g $1 | awk '
BEGIN {
        top = 1
}    
/^[ ]*[0-9][0-9]*/ {
    if ( (n = index( $2, "." )) > 0 ) {
        export_array[ top++ ] = substr( $2, n+1, length( $2 ))
    }
    else {
.export_array[ top++ ] = $2
    }
}

END {
    for ( i = 1; i < top; i++ )
    {
.print export_array[ i ]
    }

}' | sort | uniq


======================================================================

Opinions expressed here have nothing to do with IBM or my employer.
In fact, most of these opinions are borrowed from other people :)

All trademarks are the property of their respective owners.

-- 
--
.....Frank

Frank Wortner, Prodigy Services Company
mailto:frank@prodigy.com..http://pages.prodigy.com/NY/frank
Opinions are solely mine, facts belong to no one in particular.
