It is currently Tue, 17 May 2022 01:22:42 GMT



 
Author Message
 Double Variables in a Shell Script - Help Please
Greetings,

OS=HP-UX 11.11, K Shell Script

Not sure I am doing it correct, basically I am trying to avoid CASE and
lengthy code if possbile.

Here is what I want to do:

HOST_NAME=$(hostname)
PORT_NUMBER="2100 2300 2400 2500"

# Get the Queues for each Port. A port can have multipile queues
# Each queue  can be queried for  "TOTAL, BACKLOG, Inserts, Updates
Deletes, etc.,"

for Port in $PORT_NUMBER
do
    Queue${Port}=$(echo " port $Port \n qstatus " |sp_ctrl |egrep -i
Name |cut -f5 -d" ")
     # I expect Queue2100=A1_queue A2_queue A3_queue
     # Queue2200=B1_queue  B2_queue
     # Que2300=C1_queue
     # Queue2400=D1_queue  D2_queue  D3_queue
     # each port can have multiple queues
     # Process each Queue Elements one by one
      for Queue in ${QUEUE${Port}}                       # This is not
working ????
      do
          set -A B $(echo "port $Port  \n  show post queue $Queue
detail" lsp_ctrl |           egrep -i
'backlog|total|processed|inserts|deletes|updates')
          # set the port to 2100 and  Query the gien Queue and assing
it to Array B
          #sp_ctrl is the executable
          echo ${B[*]}
           # Manipulate Array B to generate an Insert statement into an
oracle Database
           # I have the Code working for this. Collect Insert Statement
for each port and its       Queues

            cat <<EOF >>bn1.sql
insert into system.nnos_splex_stats

(HOST_NAME,INSTANCE_NAME,QUEUE_NAME,PORT_NUMBER,STATUS,OPERATIONS_POSTED,PROCESSING_DATE,
   TOTAL,BACKLOG,REDOL_LOG,LOG_OFFSET,
INSERTS,UPDATES,DELETES,SQL_CACHE_HIT_PERCENT,LAST_COLLECTED)
 values
('${HOST_NAME}','$ORACLE_SID','$QUEUE_NAME',$PORT_NUMBER,'${B[1]}',${B[2]},
 to_date('${B[3]} ${B[4]}','mm/dd/yyyy hh24:mi:ss'),
${B[5]},${B[6]},${B[9]},
${B[12]},${B[23]},${B[27]},${B[31]},${B[43]},sysdate);
EOF

done   # end of For loop for all the Queues for a given port
done   # end of for loop for given ports

Appreciate your Help and Suggestions

Regards & Thanks
BN



 Sat, 25 Oct 2008 08:32:03 GMT   
 Double Variables in a Shell Script - Help Please

Some hints:
o take a look at and/or "play"(/test) with eval
o use small test sets and bits of script, and use the -v and -x
  options to help better understand how the shell is parsing,
  interpreting, and processing your script
o use/consider array variables (as long as you're using Korn or
  reasonably compatible shell)
o keep in mind the order in which the shell interprets and applies
  various substitutions.

$ n=5
$ foo${n}=50
ksh: foo5=50: not found
$ eval foo${n}=50
$ echo $foo5
50
$



 Sat, 25 Oct 2008 09:57:39 GMT   
 Double Variables in a Shell Script - Help Please

To make the assignment, under AIX and ksh88 or ksh93, i use:

VARIABLE[$COUNT]=

Then to use the variable I use:

${VARIABLE[$COUNT]}

This works much better under ksh93 than ksh88 I've found.

Miles



 Sat, 25 Oct 2008 23:59:14 GMT   
 
   [ 3 post ] 

Similar Threads

1. file contents into variable, or global variable from shell script

2. Double dereferencing Bourne shell variables

3. export variables to calling shell in a shell-script

4. Shell Variables: Shell prompt OK, script, NO.

5. help for newbie: way to get the value of an awk variable in a shell script

6. Passing a variable from a Perl script to a shell script

7. Passing a variable between shell script and perl script

8. export variables to calling shell in a shell-script

9. help with variable in shell script


 
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software