1833012 Members
2680 Online
110048 Solutions
New Discussion

Script help required...

 
SOLVED
Go to solution

Script help required...

Hi folks,

I am trying to automate a process around doing a vgimport on a host... I have my map file, and a list of disks to go in the vg - the list of disks is generated in the order:

c1t0d0
c2t0d0 (alt link)
c1t1d0
c2t1d0 (alt link)
c1t2d0
c2t2d0 (alt link)
c1t3d0
c2t3d0 (alt link)

etc...

However I want the volume group to be created with load balancing down the channels, so when the vgimport occurs, I want the order to be:

c1t0d0
c2t0d0 (alt link)
c2t1d0
c1t1d0 (alt link)
c1t2d0
c2t2d0 (alt link)
c2t3d0
c1t3d0 (alt link)

Now I know the algorithm to do this is -

start
read two lines - write two lines
read two lines - swap order of lines and write
goto start until complete

But I'm struggling to turn this into a shell or awk script...

Any ideas will earn points

Thanks

Duncan

I am an HPE Employee
Accept or Kudo
4 REPLIES 4
Justo Exposito
Esteemed Contributor

Re: Script help required...

Hi,

Try using sort:

sort -t"t" -k2 filename

Regards,

Justo.
Help is a Beatiful word
Andreas Voss
Honored Contributor
Solution

Re: Script help required...

Hi,

try this one:

awk 'BEGIN{p="";s=0;}{
if(p=="")
{
p=$0;
}
else
{
if(s==0)
{
print p;
print $0;
s=1;
}
else
{
print $0;
print p;
s=0;
}
p="";
}
}'

Regards
Robin Wakefield
Honored Contributor

Re: Script help required...

Hi Duncan,

How about:

==================
awk '
BEGIN{a=1}
{l=$0;getline
if (a==1){print l;print}
else
{print;print l}
a*=-1}' file
==================

Rgds, Robin
John Palmer
Honored Contributor

Re: Script help required...

If you wanted a shell script to do it then...

#!/usr/bin/sh

let FLAG=0

| {

while read DISK
do
read ALTDISK

if (( FLAG & 1 ));
then print "${ALTDISK}"
print "${DISK}"
else print "${DISK}"
print "${ALTDISK}"
fi
let FLAG=FLAG+1
done
}


Regards,
John