LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash script needed with 2 variables for AIX . (https://www.linuxquestions.org/questions/programming-9/bash-script-needed-with-2-variables-for-aix-660300/)

rajveervashisth 08-04-2008 05:51 AM

Bash script needed with 2 variables for AIX .
 
Hi ,

I need a bash script which can do following

mkvdev -vdev $i -vadapter vhost2 -dev bd2_app$j

where $i is the hdisk name (variable after running cfgmgr)
and $j is the second variable which is just like a label.

so if there are 5 hdisks .
I require,
a) it should ask me what should be j to start from (ex: 59)
b) it increment j till 64 (for 5 i )

and run following


mkvdev -vdev hdisk23 -vadapter vhost2 -dev bd2_app59
mkvdev -vdev hdisk24 -vadapter vhost2 -dev bd2_app60
mkvdev -vdev hdisk25 -vadapter vhost2 -dev bd2_app61
mkvdev -vdev hdisk26 -vadapter vhost2 -dev bd2_app62
mkvdev -vdev hdisk27 -vadapter vhost2 -dev bd2_app63

rajveervashisth 08-04-2008 05:55 AM

although I tried doing like this ;), but it require me to type both the variable to a file under different column

i/p

cat pqr
1 a
2 b
3 c
4 d
5 e

cat sample_twovari
for i in `cat pqr | awk {'print $1'}`
do
j=`grep $i pqr | awk {'print $2'}`
echo " I Love $i and $j"
done

o/p
I Love 1 and a
I Love 2 and b
I Love 3 and c
I Love 4 and d
I Love 5 and e

rajveervashisth 08-04-2008 07:35 AM

vi req

hdisk23 bd2_app59
hdisk24 bd2_app60

awk '{print "mkvdev -vdev",$1,"-vadapter vhost2 -dev",$2}' req > run

ksh +x run

rajveervashisth 08-05-2008 12:31 AM

Got the answer:

#Move old files

ND=/home/rajveerv/newdisk.out
mv $ND "$ND".old

NL=/home/rajveerv/newlabel.out
mv $NL "$NL".old


#Getting newly added disk info
grep -Fvf lspv.bef lspv.aft | awk {'print $1'} > $ND


#Getting label info
echo "input the label Name: ex:bd2_app"
read m
echo "input the starting number:"
read i
r=`wc -l $ND | awk {'print $1'}`
j=$i+$r
while (( i<j ));
do
echo "$m$i" >> $NL
(( i = i + 1 ));
done

paste -d' ' $ND $NL > req

awk '{print "Disk Name is: ",$1,"And the Label is :",$2}' req > run


All times are GMT -5. The time now is 03:33 PM.