Monday, February 16, 2009

Passing in a shell variable to AWK program used as a match pattern

I have a need to get the backlog message of a shareplex replicaton queue based on the queue name, I am not aware that there is a simple command in SharePlex to do it. So I developed a script. I have learned how to pass in a shell variable to the AWK program. This variable will thus be used as a match pattern in the AWK program.

The outoput of the SharePlex command I know to show the backlog messages looks like:

$ sp_ctrl qstatus on myhostname

Queues Statistics for myhostname
Name: QueueD (o.prddb-o.rptdb) (MTPost queue)
Number of messages: 11825 (Age 7 min; Size 21547 mb)
Backlog (messages): 126 (Age 0 min)

Name: QueueA (o.prddb-o.rptdb) (MTPost queue)
Number of messages: 809345 (Age 48 min; Size 414840 mb)
Backlog (messages): 806421 (Age 44 min)

Name: QueueB (o.prddb-o.rptdb) (MTPost queue)
Number of messages: 49512 (Age 158 min; Size 71059 mb)
Backlog (messages): 14425 (Age 4 min)

Name: QueueC (o.prddb-o.rptdb) (MTPost queue)
Number of messages: 9678 (Age 8 min; Size 129632 mb)
Backlog (messages): 155 (Age 0 min)

Name: QueueE (o.prddb-o.rptdb) (MTPost queue)
Number of messages: 2 (Age 0 min; Size 28042 mb)
Backlog (messages): 0 (Age 0 min)




My script:



----- script backlog_q.sh -------
#!/bin/ksh
# script bakclog_q.sh
# display backlog of a queuue

qname="QueueB"
sp_ctrl qstatus on myhostname /usr/xpg4/bin/awk -v pat="$qname" '
begin
{
if ( $0 ~ pat ) {
getline
getline
print $3
}
}' read backlog

echo $backlog

---- end of the script --------

No comments: