1831677 Members
2180 Online
110029 Solutions
New Discussion

Re: Script help

 
SOLVED
Go to solution
Mike_305
Super Advisor

Script help

Hi,

I need help with a small loop script. In the loop below I need to set variable that will change the LUN number from 1 to 2 to 3 and so on and when the number reaches to 110 the script will exit.

What statement for variable I can use?

LUN= (what I can use here will change the number and stop the script when it goes to 110)

while true

do

armcfg -L $LUN -a 10G -g 1 va74xx

done

exit

If I can’t get the answer from the guru’s then I guess I am typing.

Thanks,

Mi
If there is problem then don't think as problem, think as opportunity.
7 REPLIES 7
Ed Loehr
Advisor
Solution

Re: Script help

There is a nifty 'seq' command on Linux, but...

for LUN in `perl -e 'for($i=1;$i<=110;$i++){print "$i\n";}'`; do armcfg -L $LUN -a 10G -g 1 va74xx; done
Mike_305
Super Advisor

Re: Script help

Hi,

I try to run this and I get following error.

Missing $ on loop variable at ./test.pl line 4.

Any idea.

Thanks,

Mike
If there is problem then don't think as problem, think as opportunity.
T G Manikandan
Honored Contributor

Re: Script help

i=1
while [ : ]
do
armcfg -L $i -a 10G -g 1 va74xx
i=`expr $i + 1`
if [ $i -gt 110 ]; then
break
fi
done
Hein van den Heuvel
Honored Contributor

Re: Script help

Minor variation:

for a in `perl -e 'print "$i " while (++$i<10)'` ; do echo test $a test ; done

or with awk:

for a in `awk 'BEGIN {while (++i<10){ print i}}'` ; do echo test $a test ; done

Personally I prefer to stay in perl/awk and just generate and execute the command to be executed, or... just make them generate a file with the commands to execute, review, and execute the file:

perl -e 'print "armcfg -L $i -a 10G -g 1 va74xx" while (++$i<110)' > x
view x
chmod +x x
./x

Cheers,
hein.
`
Muthukumar_5
Honored Contributor

Re: Script help

We can do this with while loop of shell as,

LUN=1
while [[ $LUN -le 110 ]]
do

armcfg -L $LUN -a 10G -g 1 va74xx

let LUN=LUN+1

done

It will do this.

Easy to suggest when don't know about the problem!
Muthukumar_5
Honored Contributor

Re: Script help

We can use until loop to for this.

until [[ $i -gt 110 ]]; do
armcfg -L $i -a 10G -g 1 va74xx
let i=i+1
done

To use loop we have to go to awk programming only as,

echo "1 110" | awk '{
for (i=$1;i<=$2;i++) print $i system cmd to execute armcfg here.. }'

Use while / until to do easily more
Easy to suggest when don't know about the problem!
Mike_305
Super Advisor

Re: Script help

Thanks Guys for your help.

Mike
If there is problem then don't think as problem, think as opportunity.