Thanks everybody,
let's see:
Quote:
Originally Posted by
zaxxon
I guess the problem is, that the mdadm stuff is in the background and will move on to the next command while it is still executing in the background.
Zaxxon you are completely right.
Zaxxon also pointed out that either checking if there are still processes "mdadm" up or if the desired partitions, array has been created would be the solution, but the problem is that I don't know how to control that and I don't know what would be the actual programing solution.
About the "including an sleep" option, that is not the best choice if we are looking for a portable design.
Jazmania, sorry but I don't understand what exactly is a .done file (I have just began to use shell script and I don't have any previous programing skills). Anyway I think that as far as I understood we will still have the same problem. You said "touch some sort of .done file at the end of it's run" but I can't determinate whether the mdadm reach the end of his run.
By myself yesterday I found a new solution:
At the end of the process, when the raid has been properly created, in my case, the result that we got with the cat /proc/mdstat is:
Personalities : [raid1]
md3 : active raid1 sdb4[0] sda4[1]
1951808 blocks [2/2] [UU]
md2 : active raid1 sdb3[0] sda3[1]
17575040 blocks [2/2] [UU]
md1 : active raid1 sdb2[0] sda2[1]
29294400 blocks [2/2] [UU]
md0 : active raid1 sdb1[0] sda1[1]
29294400 blocks [2/2] [UU]
unused devices: <none>
Firtsable a make a temp file with this content:
cat /proc/mdstat | grep UU > stat2.txt
This is inside stat2.txt:
1951808 blocks [2/2] [UU]
17575040 blocks [2/2] [UU]
29294400 blocks [2/2] [UU]
29294400 blocks [2/2] [UU]
And then I designed this code:
#!/bin/bash
mdadm --manage /dev/md0 --add /dev/sdb1
mdadm --manage /dev/md1 --add /dev/sdb2
mdadm --manage /dev/md2 --add /dev/sdb3
mdadm --manage /dev/md3 --add /dev/sdb4
cat /proc/mdstat | grep UU > stat1.txt
cmp stat1.txt stat2.txt > /dev/null
until [ $? -eq "0" ]
do
cat /proc/mdstat | grep UU > stat1.txt
cmp stat1.txt stat2.txt > /dev/null
sleep 2
done
exit 0
In this code I'm comparing whether we have reached the raid creation. A properly raid creation will show us "UU" in all of the disks, thus, the "grep" command is looking for copy the lines with the "UU" messages to a temp file (stat1.txt)
I have already put a copy of how should look the right design into stat2.txt.
Until the cmp command returns a 0, the loop will place the new output of the cat /proc/mdstat in stat1.txt.
Notice: As you see this works just for this case, I would like to made my code portable.
Zaxxon I'm looking forward to see if you can give me some code solution for checking if mdadm processes (or any kind of processes) are still active. I think that that would be the best.