Scripting question
I didn't understand all that you were trying to do so here are some general pointers.
Korn shell supports arrays. You could pull your data in seperate arrays for node, cust and mb then do a loop on the array counter.
while loops often work better than for loops.
i=0
while [ -n "$cust[$i]" ]
do print "$node[$i] $cust[$i] $mb[$i]
i=$(( i + 1 ))
done
Quoted 35 lines · Michael French
I have a couple of scripts that I am working on that pull data from an
application and print a human readable report from the data. I have all of the data pulled and stored in variables, but I am stumped on how to put in all in one file. I hope that I can clearly explain this, here goes.For one script, I have three pieces of info to report: node name,
customer name, and total data stored. The first two bits of data are getting pulled out together and stored in one file. The third bit is being calculated and then stored in a second file. I then get the data in like this:NODES=
cat nodeinfo.txt | awk '{print $1}'
CUSTOMER=cat nodeinfo.txt | awk '{print $2}'
MBTOTALS=cat mbtotals.txtI then need to print out a report like:
Nodes Customer MB
----------------------------------
node1 customer1 20.0How can I do this? I can't seem to figure out how to do it with one for loop.
I have another little script I am working on to report restore data and
it has one temp file holding all of the info I need and is greping out about 10 different pieces of data I need before overwriting the temp file with the info on the next node. The problem I have run into is that some of the restores have duplicate data in them so I am going to have to rewrite the report to put the data in variables and then loop through them to generate a report just like the one above, except with more variables so you can see why I am trying to figure out how to do this as cleanly as possible. Maybe I am starting off all wrong so feel free to redirect me. Also, I am using Korn shell to do this (my only option).
Quoted 9 lines
Thanks!
Michael French
-
To unsubscribe from this list: send the line "unsubscribe linux-admin" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
__________________________________________________________________
The NEW Netscape 7.0 browser is now available. Upgrade now! http://channels.netscape.com/ns/browsers/download.jsp
Get your own FREE, personal Netscape Mail account today at http://webmail.netscape.com/
23.01.03 18:49:24, [email protected] wrote:
[...]
Quoted 2 lines
Korn shell supports arrays. You could pull your data in seperate arrays for node, cust and mb then do a loop on the array counter.
[...]
Not only Korn shell, bash (2.x) does it either.
liana:~$ bash --version GNU bash, version 2.05b.0(1)-release (i386-pc-linux-gnu) Copyright (C) 2002 Free Software Foundation, Inc.
liana:~$ man bash
[...]
Arrays
Bash provides one-dimensional array variables. Any variable may be
used as an array; the declare builtin will explicitly declare an
[...]