Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Hello,
I need some help here please. I wrote a script that generates a fanout ratio, basically how many servers beind an FA pair (rule of 17 applies). Here is report.out
Type DIR Port Total
-----------------------------
HP 11A 0 0
HP 11A 1 0
HP 12B 0 10
HP 12B 1 14
HP 13B 0 8
HP 14B 0 12
HP 3B 0 13
HP 4B 0 8
HP 5B 0 10
HP 5B 1 15
HP 6A 0 0
HP 6A 1 0
SWAL 12A 0 4
SWAL 12A 1 2
SWAL 13A 0 7
SWAL 13A 1 12
SWAL 13B 1 8
SWAL 14A 0 14
SWAL 14A 1 0
SWAL 14B 1 3
SWAL 3A 0 14
SWAL 3A 1 0
SWAL 3B 1 3
SWAL 4A 0 7
SWAL 4A 1 12
SWAL 4B 1 8
SWAL 5A 0 4
SWAL 5A 1 2I want to print this report using this pattern bellow:
HP 11A 0 0
HP 6A 0 0
HP 11A 1 0
HP 6A 1 0
HP 12B 0 10
HP 5B 0 10so on ... You can see on column2 a patern of 17 for each two lines.
Thank you in advance

let me be more explicit. The rule of 17 is as follow:
Two FA pairs are like 11A/6A or 13B/4B or 14C/3C ....and a pair is either using port 0 or 1 on third column of file I uploaded. So having a sorted report make it much easier to see hosts distribution on each pair.
Any help I would appreciate.

ok, I think I get it now, let me know if this is correct. you want to sort based on: the sum of two rows, whose second column adds up to 17 AND where both rows have a 0 or a 1 on the third column?
What about the SWAL ones? Does the letter after the number in the second column make and difference?

Ok, i pretty much have it done. just a few questions
1) Will something in the HP section ever match something in the SWAL section?
2) Would there ever be more than one match? Say:
HP 11A 0 0
HP 6A 0 0
HP 6A 0 8
3) Do the letters in the second column, after the number, have to match? Or can you have
HP 11A 0 0
HP 6B 0 0

Nope. The HP section is dedicated to HP but randomly defined on each storage array. This example you asked here is not a pair.
HP 11A 0 0
HP 6B 0 0btw SWAL means SUN, WINDOWS,AIX, LINUX
on that section too you will have it displayed as
SWAL 12A 1 2
SWAL 5A 1 2
SWAL 13A 0 7
SWAL 4A 0 7
SWAL 13C 0 3
SWAL 4C 0 3
SWAL 8C 0 2
SWAL 9C 0 2so on ....
What is 100% sure is file will always have an even # of lines as it must meet the 17 rule for a pair.
Thanks,

ok, try the following script. all you need to is enter the input filename as an argument when running the script
#!/usr/bin/ksh fname=$1 if [[ $1 = "" ]];then print "Enter a filename!" else cp $fname $fname.tmp while read lines;do ## Break up the fields first=$(print $lines|cut -f1 -d" " ) second=$(print $lines|cut -f2 -d" " ) third=$(print $lines|cut -f3 -d" " ) fourth=$(print $lines|cut -f4 -d" " ) ## Break up the second field secnum=$(print $second|tr -d "[:alpha:]") seclet=$(print $second|tr -d "[:digit:]") ## Find what is needed numneed=$((17-$secnum)) ## Find needed line isneeded="$first $numneed$seclet $third $fourth" isfound=$(grep "$isneeded" $fname.tmp) if [[ $isfound != "" ]];then print $first $second $third $fourth print $isneeded print "" ## Ensure no duplicates grep -v "$isneeded" $fname.tmp |grep -v "$first $second $third $fourth" > $fname.t mv $fname.t $fname.tmp fi done < $fname rm $fname.tmp fialso, if you don't mind, let me know if that worked.

ok I ran the script and the output looks like this:
HP 10B 0 5
HP 10C 1 0
HP 7B 0 5
HP 7C 1 0
HP 8B 0 14
HP 9B 0 14
SWAL 10A 0 16
SWAL 10A 1 8
SWAL 10B 1 0
SWAL 10C 0 0
SWAL 7A 0 15
SWAL 7A 1 7
SWAL 7B 1 0
SWAL 7C 0 0
SWAL 8A 0 15
SWAL 8A 1 7
SWAL 8B 1 0
SWAL 8C 0 0
SWAL 8C 1 0
SWAL 8D 0 0
SWAL 8D 1 0
SWAL 9A 0 15
SWAL 9A 1 7
SWAL 9B 1 0
SWAL 9C 0 0
SWAL 9C 1 0
SWAL 9D 0 0
SWAL 9D 1 0That is huge progress though and thank you for that. Here is what I expect to get:
HP 10B 0 5
HP 7B 0 5
HP 10C 1 0
HP 7C 1 0
HP 8B 0 14
HP 9B 0 14
SWAL 10A 0 16
SWAL 7A 0 15
SWAL 10A 1 8
SWAL 7A 1 7
SWAL 10B 1 0
SWAL 7B 1 0
SWAL 10C 0 0
SWAL 7C 0 0
SWAL 8A 0 15
SWAL 9A 0 15
SWAL 8A 1 7
SWAL 9A 1 7
SWAL 8B 1 0
SWAL 9B 1 0
SWAL 8C 0 0
SWAL 9C 0 0
SWAL 8C 1 0
SWAL 9C 1 0
SWAL 8D 0 0
SWAL 9D 0 0
SWAL 8D 1 0
SWAL 9D 1 0You can see the patern on field 2,3 for each two lines from top to bottom.
Thank you again.

thats strange, it comes out ok when i run it based on the example you gave. does it throw any errors when you run it? you copied the script exactly? can you make sure tr and cut both work? independent of the script?

just tried it with the latest info you gave and got:
HP 10B 0 5 HP 7B 0 5 HP 10C 1 0 HP 7C 1 0 HP 8B 0 14 HP 9B 0 14 SWAL 10B 1 0 SWAL 7B 1 0 SWAL 10C 0 0 SWAL 7C 0 0 SWAL 8A 0 15 SWAL 9A 0 15 SWAL 8A 1 7 SWAL 9A 1 7 SWAL 8B 1 0 SWAL 9B 1 0 SWAL 8C 0 0 SWAL 9C 0 0 SWAL 8C 1 0 SWAL 9C 1 0 SWAL 8D 0 0 SWAL 9D 0 0 SWAL 8D 1 0 SWAL 9D 1 0Remember, the output wont be in a file anywhere, it just displays live to the screen. to put it to a file run it with: scriptname > outputfile

I am running it on a sun server like this:
./read.ksh 3449:FANOUT:051209.out > read.out
at them end of script, file is zero byte

also the output is not displaying on my screen if not redirected to a file unless I ran ksh -x .....

I am just starting to see if there is any difference for KSH on sun, but I can see on my box that the filename 3449:FANOUT:051209.out causes a problem. can you try to rename it to something like file.out and try it?

Looking around, there may be a KSH version difference, taken from:
http://www.unix.com/sun-solaris/369...the default ksh on solaris is a posix ksh88 (/usr/bin/ksh) but there is another ksh on solaris, the ksh93 called dtksh (/usr/dt/bin/dtksh)so failing all else, you may want to try:
/usr/dt/bin/dtksh

I renamed the file and moved it to an AIX 5.1 and same result. I am puzzled by it. why it is not prining all the print statements to either screen or a file.
I have a question though would it be better to read to read 4 parameters instead of an entire line? Also I have seen in the past on Solaris reading the input file with < at end of the while loop.
I am not geeting any error while running it but just zero byte output file.
When I get home tonight I will do more investigation and let you know.
I REALLY appreciated your help.

sure it's worth a shot, i've always just been used to doing it the other way, old habits and all:
#!/usr/bin/ksh fname=$1 if [[ $1 = "" ]];then print "Enter a filename!" else cp $fname $fname.tmp while read first second third fourth;do ## Break up the second field secnum=$(print $second|tr -d "[:alpha:]") seclet=$(print $second|tr -d "[:digit:]") ## Find what is needed numneed=$((17-$secnum)) ## Find needed line isneeded="$first $numneed$seclet $third $fourth" isfound=$(grep "$isneeded" $fname.tmp) if [[ $isfound != "" ]];then print $first $second $third $fourth print $isneeded print "" ## Ensure no duplicates grep -v "$isneeded" $fname.tmp |grep -v "$first $second $third $fourth" > $fname.t mv $fname.t $fname.tmp fi done < $fname rm $fname.tmp fiif you want to contact me directly, feel free to do so at:
lankrypt0 at gmail dot com

![]() |
![]() |
![]() |
| Login or Register to Reply | |
| Login | Register |
| Ads by Google |