Hi, I'm not realy familiar with DB2 but I see some things that might go wrong. First try your first attempt preceding with this assignment
Code:
#!/bin/ksh
. /home/db2inst1/sqllib/db2profile
export TABLES
db2 connect to tecdb
...
If that doesn't work redesign the AWK command of your second try like this:
Code:
awk '{
printf("%s \"%s %s %s %s%s.%s%s %s %s%s%s %s %s;\"\n",
"db2", "select A.schema, A.tabname, A.npages, B.pagesize,",
"C.indextype from syscat.tables A, syscat.tablespaces B,",
"syscat.indexes C where A.tabname =", quote, $1, $2, quote,
"and C.indextype =", quote, "CLUS", quote,
"and A.tbspaceid = B.tbspaceid",
"and A.tabname = C.tabname order by 3 desc")
}' quote="'" `db2 -x "CALL SYSPROC.REORGCHK_TB_STATS('T', 'ALL')" | grep '*'`
The single quote can't be used within the AWK code because the interpreter regards that as source terminator. That's why it's done here in a roundabout way by assigning the ' to a variable (quote) before the value of the db2 command is read. Printf is the formatting version of print and gives much more flexibility as you can see, it's the equivalent of the C printf function. If you're not acquainted with it: the first argument is the formatstring, which consists of placeholders for stringvariables (%s) and spaces only. The single dot in it is the dot between the table_schema and table_name. The other arguments are the subsequent literals/variables ($1 and $2 refer to the first and second field of the input record) that are substituted by the placeholders. See the man page for further information.
If that's printing the correct SQL statements (don't know what kind of UNIX system and therefore what kind of AWK you're using) complete the AWK program in a way it will execute the SQL statements as well. You can do that like:
Code:
awk '{ stmnt = sprintf("%s \"%s %s %s %s%s.%s%s %s %s%s%s %s %s;\",
...
system(stmnt)
}' quote="'" ...
With this you'll store the dynamicly build string in variable stmnt and finally execute that statement as a system command.
Good luck,
Hans