Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am working a script to create a raid5 array. The question is how to put the command in a if (to see if the command succeeded), and when the script ask to continue creating array it will auto say yes.

Here is the command:

mdadm --create --verbose /dev/md0 --level=5 --raid-devices=3 /dev/sdc1 /dev/sdd1 /dev/sde1 --spare-devices=1 /dev/sdf1
share|improve this question

1 Answer 1

This bash script should work, however I did not test it. It does literally check if last command status is different then 0 (OK) if not then (FAIL).

#!/bin/bash
mdadm --auto=yes ...
if [ $? -eq 0 ]; then
    echo OK
else
    echo FAIL
fi

Read the manual here: http://www.linuxmanpages.com/man8/mdadm.8.php it says more about parameters and the flag --auto. Also it should tell you more about return status codes, so you can add the case scenarios to your bash script.

share|improve this answer
    
I get this fault: mdadm: --auto does not set the mode, and so cannot be the first option. FAIL –  user3185936 Feb 16 at 15:24
    
Try moving the --auto flag after the --spare-devices=1. Synopsis for that command is: mdadm [mode] <raiddevice> [options] <component-devices> –  NeverEndingQueue Feb 16 at 15:29
    
The scripts runs now, but it still asks me if I want to continue creating array. So that means that --auto=yes didn't work. –  user3185936 Feb 16 at 15:31
    
I don't have opportunity to test it, so I am doing it blind, however the point is to put option between your raiddevice and compontent-devices. Assuming that your raiddevice is the /dev/md0 and your component devices are: /dev/sdc1, /dev/sdd1, /dev/sde1 and /dev/sdf1 you need to add option --auto for e.g after the --raid-devices flag. Also you should move: --spare-devices following the same logic (as it's possibly ignored right now). Give it a try. If it does not work then someone more familiar with that command should be able to help. –  NeverEndingQueue Feb 16 at 15:46
    
Thank you, for your help and time! I have tried different methods of placing the auto flag. It's not looking good. Hopefully someone who have encountered this fault will help. –  user3185936 Feb 16 at 15:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.