0

I am trying to write a dd migration script that will do the following:

  1. read user input (max=4) into an array, called "array". the user will enter the logical volume names to be migrated.
  2. once each element is stored on an array, run:

/sbin/lvscan | grep -E '"array[0]"|"array[1]"|"array[2]"|"array[3]"’

  1. spawn multiple ssh connections to migrate each logical volume via dd to a specific host, the IP of which is also entered by user and stored in a variable.

I currently have:

#!/bin/bash

 echo "Enter upto 4 SRVID's seperated by a space"


 while read SRVIDS 
 do


        [ "$SRVIDS" == "done" ] && break
        array=("${array[@]}" $SRVIDS)

 done



 /sbin/lvscan | grep -E '"array[0]"|"array[1]"|"array[2]"|"array[3]"' 2&>1

What am I doing wrong? I am unable to get grep for the logical volume paths.

2
  • 1
    Variables/arays names are not expanded under single quotes, you need to remove them. Also add $ in front of their names.
    – jimmij
    Commented Dec 4, 2018 at 5:14
  • Getting the volume names on the command line would make the script more flexible.
    – Kusalananda
    Commented Dec 4, 2018 at 11:39

1 Answer 1

1

No need to list ALL the array elements; try:

IFS="|"
grep -E "${array[*]}"

Don't forget to save old IFS and then restore it...

1
  • ... or do it in a subshell.
    – Kusalananda
    Commented Dec 4, 2018 at 12:33

You must log in to answer this question.