bashcommandubuntu-12.04raidmdadm

Auto yes to raid5 array script


I am working on a script to install a array raid5. I am having trouble with inserting auto=yes when the script ask: if I want to continue creating array. I tried --auto=yes (http://www.linuxmanpages.com/man8/mdadm.8.php) but very unsure where to place it.

#!/bin/bash
mdadm mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sdc1 /dev/sdd1 /dev/sde1 --spare-devices=1 /dev/sdf1

if [ $? -eq 0 ]; then
    echo OK
else
    echo FAIL
fi

Solution

  • 1) you can use HEREDOC to resolve such problems.

    for example for passwd command:

    #!/bin/bash
    passwd user <<EOF
    mypassword
    mypassword
    EOF
    

    You can also run your script and put heredoc :

    ./script <<EOF
    >yes
    >yes
    >no
    >EOF
    

    UPDATE:

    This is finally what you want

    if you have one question:

    ./script <<EOF
    >yes
    >EOF
    

    Also you can:

    #!/bin/bash
    mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sdc1 /dev/sdd1 /dev/sde1 --spare-devices=1 /dev/sdf1 <<EOF
    yes
    EOF
    

    2) There is also another solution:

    yes | command-that-asks-for-input
    

    or, if a capital 'Y' is required:

    yes Y | command-that-asks-for-input