Help required in shell script

I am writing shell script to create PV,VG,LVM and mountpoint and FS.

1. I am getting not-root disks using below command

PDEVICE=`lsscsi --device | grep -v "\:0\]$" | awk '/dev/{for(i=1;i<=NF;i++)if($i~/dev/)print $i}'`

Open in new window


2. Getting the PV's and checking whether the specific PV has attached to any VG or not as below.

VDEVICE=`/sbin/pvs | egrep -iv "(rootvg|PV)"  | awk '{print $1}'`

Open in new window


3. After that comaring these two arrays which PV's are not added to VG so that i am trying to add the missed devices to VG but some logic i am missing here ... can any one help in this ASAP please.

#! /bin/bash



PDEVICE=`lsscsi --device | grep -v "\:0\]$" | awk '/dev/{for(i=1;i<=NF;i++)if($i~/dev/)print $i}'`

echo ${PDEVICE[@]}


VDEVICE=`/sbin/pvs | egrep -iv "(rootvg|PV)"  | awk '{print $1}'`


echo ${VDEVICE[@]}

echo "Comparing the both the PV values"

for i in "${PDEVICE[@]}"
 do
    for j in "${VDEVICE[@]}"
 do
     if [ "${i[@]}" != "${j[@]}" ]
     then
      echo "${i[@]}"
     else
       echo "${j[@]}"
fi

done
done

Open in new window

LVL 1
BharathKumarRaju DasaraRajuDevops EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Here's how I approach this type of complex problem.

I tend to use PERL, as managing complex variable expansion tends to be simpler.

Then build up all the commands to run + first just echo each command.

Then take the echoed commands + execute them manually.

Once you can execute a manual sequence with zero errors, then just add system($command) calls to each echoed command.

If you must use bash (shudder), turn on command echoing, so you can see what commands you're actually running.

This simple step surfaces most problems. You do this by adding the following under your #! line.

set -x

Open in new window

0
BharathKumarRaju DasaraRajuDevops EngineerAuthor Commented:
sorry I dont know perl at all
0
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Then adding set -x to your script will be your next step, so you can actually see exactly what command is executing.
0
Gerwin Jansen, EE MVETopic Advisor Commented:
Provide sample data for ${PDEVICE[@]} and ${VDEVICE[@]} - real data.

Add a new line #21:

echo "Comparing ${i[@]} with ${j[@]}" ; read line

Adding a "set -xf" line will help to show what's happening.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
BharathKumarRaju DasaraRajuDevops EngineerAuthor Commented:
Thank you!!!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Linux

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.