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[@]}"
    for j in "${VDEVICE[@]}"
     if [ "${i[@]}" != "${j[@]}" ]
      echo "${i[@]}"
       echo "${j[@]}"


Open in new window

BharathKumarRaju DasaraRajuDevops EngineerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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

BharathKumarRaju DasaraRajuDevops EngineerAuthor Commented:
sorry I dont know perl at all
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.
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.

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!!!
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

From novice to tech pro — start learning today.