Skip to contentSkip to conversation

Scripting question

DISCUSSION Michael French 5 participants 7 messages Jan 23, 2003 – Jan 24, 2003

lore
Share & tools
lore
#0 lore raw

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.txt

I then need to print out a report like:

Nodes Customer MB
----------------------------------
node1 customer1 20.0

How 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).

Thanks!

Michael French

#1 lore raw

Hi Michael,
Switch to PERL. You open the input files, then open the output file,
sort, and write. Perhaps if there are duplicates, you need additional information, like a datestamp for each entry to compare.

(.02) - Andrew

Quoted 44 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.txt

I then need to print out a report like:

Nodes Customer MB
----------------------------------
node1 customer1 20.0

How 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).

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

#2 lore raw
In reply to Michael French

everyone is gonna tell you to learn a "real" scripting language, but i wont.
yeah, shell scripts are slow and ugly but, after all, it works, and its easier than blowing your nose.
anyway i dont have the time to learn perl, so there.

i think it would be easiest to first combine the two files nodeinfo.txt and mbtotals.txt into one with three columns, using for example any spreadsheet program.
then you can just do something like:
while read LINE
do
NODES=echo $LINE | awk '{print $1}'
CUSTOMER=echo $LINE | awk '{print $2}'
TOTAL=echo $LINE | awk '{print $3}'
echo -e $NODES\t$CUSTOMER\t$TOTAL >> tmpfile
done < nodeinfo.txt

its much easier to work with one file only. otherwise, all i can think of is using sed/awk somehow. maybe like:
while read LINE
do
NODES=as above
CUSTOMER=as above
WHAT_LINE_ARE_WE_ON=1
TOTALS=<use awk or sed to print the Nth line of mbtotals.txt, ie the $WHAT_LINE_ARE_WE_ONth line>
add one to $WHAT...
echo all to a file >> tmpfile
done < nodeinfo.txt

Quoted 60 lines

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.txt

I then need to print out a report like:

Nodes Customer MB
----------------------------------
node1 customer1 20.0

How 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).

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

#3 lore raw

There's also paste if the hook up needs to be on identical records.

Signature · 1 line
Jude <dashielljt(at)gmpexpress-dot-net>
#4 lore raw
In reply to Michael French

Got Perl?
---
#!/usr/bin/perl

format STDOUT_TOP =
Nodes Customer MB
----------------------------------
.

format =
@<<<<<<<<<<< @<<<<<<<<<<<<<< @>>>>
$1,$2,$3
.

(open A,$ARGV[0]) && (open B,$ARGV[1]) or die $!;
write while split ' ',<A>.<B>;
---

Invoke as one of:
script nodeinfo.txt mbtotals.txt
script - mbtotals.txt < nodeinfo.txt
script nodeinfo.txt - < mbtotals.txt

== Rich

Quoted 49 lines · Michael French

Date: Wed, 22 Jan 2003 21:14:15 -0800
From: Michael French <[email protected]>
To: [email protected]
Subject: Scripting question

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.txt

I then need to print out a report like:

Nodes Customer MB
----------------------------------
node1 customer1 20.0

How 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).

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

#5 lore raw

Oops, change the "$1,$2,$3" to "$@" == Rich

Quoted 85 lines · On Thu, 23 Jan 2003 [email protected] wrote:

Date: Thu, 23 Jan 2003 16:46:51 -0800 (PST)
From: [email protected]
To: Michael French <[email protected]>
Cc: [email protected]
Subject: Re: Scripting question

Got Perl?
---
#!/usr/bin/perl

format STDOUT_TOP =
Nodes Customer MB
----------------------------------
.

format =
@<<<<<<<<<<< @<<<<<<<<<<<<<< @>>>>
$1,$2,$3
.

(open A,$ARGV[0]) && (open B,$ARGV[1]) or die $!;
write while split ' ',<A>.<B>;
---

Invoke as one of:
script nodeinfo.txt mbtotals.txt
script - mbtotals.txt < nodeinfo.txt
script nodeinfo.txt - < mbtotals.txt

== Rich

Quoted 49 lines · Michael French

Date: Wed, 22 Jan 2003 21:14:15 -0800
From: Michael French <[email protected]>
To: [email protected]
Subject: Scripting question

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.txt

I then need to print out a report like:

Nodes Customer MB
----------------------------------
node1 customer1 20.0

How 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).

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

#6 lore raw

Thanks for the help everyone, I was able to do it with John Julian's
while loop, worked like a champ!

Michael

In case you missed, here's the code:

i=0
while [ -n "$cust[$i]" ]
do print "$node[$i] $cust[$i] $mb[$i]
i=$(( i + 1 ))
done

----- Original Message -----
From: <[email protected]>
To: "Michael French" <[email protected]>
Cc: <[email protected]>
Sent: Thursday, January 23, 2003 4:50 PM
Subject: Re: Scripting question

Quoted 43 lines

Oops, change the "$1,$2,$3" to "$@" == Rich

Quoted 39 lines · On Thu, 23 Jan 2003 [email protected] wrote:

Date: Thu, 23 Jan 2003 16:46:51 -0800 (PST)
From: [email protected]
To: Michael French <[email protected]>
Cc: [email protected]
Subject: Re: Scripting question

Got Perl?
---
#!/usr/bin/perl

format STDOUT_TOP =
Nodes Customer MB
----------------------------------
.

format =
@<<<<<<<<<<< @<<<<<<<<<<<<<< @>>>>
$1,$2,$3
.

(open A,$ARGV[0]) && (open B,$ARGV[1]) or die $!;
write while split ' ',<A>.<B>;
---

Invoke as one of:
script nodeinfo.txt mbtotals.txt
script - mbtotals.txt < nodeinfo.txt
script nodeinfo.txt - < mbtotals.txt

== Rich

Quoted 6 lines · Michael French

Date: Wed, 22 Jan 2003 21:14:15 -0800
From: Michael French <[email protected]>
To: [email protected]
Subject: Scripting question

I have a couple of scripts that I am working on that pull data

from an

Quoted 1 line
Quoted 1 line
Quoted 1 line

application and print a human readable report from the data. I have

all of

Quoted 1 line
Quoted 1 line
Quoted 1 line

the data pulled and stored in variables, but I am stumped on how to

put in

Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

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

Quoted 1 line
Quoted 1 line
Quoted 1 line

calculated and then stored in a second file. I then get the data in

like

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

this:

NODES=cat nodeinfo.txt | awk '{print $1}'
CUSTOMER=cat nodeinfo.txt | awk '{print $2}'
MBTOTALS=cat mbtotals.txt

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines

I then need to print out a report like:

Nodes Customer MB
----------------------------------
node1 customer1 20.0

How can I do this? I can't seem to figure out how to do it with one

for

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

loop.

I have another little script I am working on to report restore

data and

Quoted 1 line
Quoted 1 line
Quoted 1 line

it has one temp file holding all of the info I need and is greping out

about

Quoted 1 line
Quoted 1 line
Quoted 1 line

10 different pieces of data I need before overwriting the temp file

with the

Quoted 1 line
Quoted 1 line
Quoted 1 line

info on the next node. The problem I have run into is that some of

the

Quoted 1 line
Quoted 1 line
Quoted 1 line

restores have duplicate data in them so I am going to have to rewrite

the

Quoted 1 line
Quoted 1 line
Quoted 1 line

report to put the data in variables and then loop through them to

generate a

Quoted 1 line
Quoted 1 line
Quoted 1 line

report just like the one above, except with more variables so you can

see

Quoted 1 line
Quoted 1 line
Quoted 1 line

why I am trying to figure out how to do this as cleanly as possible.

Maybe

Quoted 1 line
Quoted 1 line
Quoted 1 line

I am starting off all wrong so feel free to redirect me. Also, I am

using

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Korn shell to do this (my only option).

Thanks!

Michael French

-
To unsubscribe from this list: send the line "unsubscribe linux-admin"

in

Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html