Adding physical RAID disks via BASH script?
Hello,
I am writing a script which adds a hard disk to existing raid configuration. Here is how the script goes: Code:
5 Slot Number: 0 - Online, Spun Up Slot Number: 1 - Online, Spun Up Slot Number: 2 - Online, Spun Up Slot Number: 3 - Online, Spun Up Slot Number: 4 - Unconfigured(good), Spun Up Slot Number: 12 - Unconfigured(good), Spun Up You have chosen to add drives to RAID. Please wait.. ./lsi.sh: line 109: $'\r': command not found [root@localhost ~]# Actually if I run manually the command look like: [root@testmachine ~]# /usr/sbin/MegaCli -LDRecon -Start -r5 -Add -PhysDrv[32:3] -l0 -a0 Start Reconstruction of Virtual Drive Success. Exit Code: 0x00 All it does is adding the newly hard drive to RAID. Please suggest what is correct way with this code: Code:
echo $drives | while IFS=" :" read _ _ slot _ status; do if [[ $status != "Online, Spun Up" ]]; then aslot=${slot%:}; `$MegaCli -LDRecon -Start -r$raidlevel -Add -PhysDrv[$ENCLOSURE:$aslot] -l0 -a0` ; fi; done |
Well we are obviously only getting a snippet, as error is at line 109, but my suggestion would either be to turn on debugging (set -xv) or echo the command prior to calling.
There are 2 issues I can see straight off though: 1. Your read is already using IFS=' :' so then the following would be pointless as there would be no ':' in the variable: Code:
aslot=${slot:} On a side note, you could re-write nearly all you have shown to be much tidier as there is almost never a reason to use multiple awk's on a single line and also, awk can do all the jobs of sed, grep and cut |
Thanks. I got it working. http://www.shellcheck.net/ helped me too.
|
This site works on people learning from each other, so it would be nice if you would share with others what the solution was :)
|
grail,
The code which worked is here Code:
Is there any way I can run it in parallel. Say, if I add two hard disk, both of them should start reconstructed parallel. How will the code look like? |
I am not familiar with MegaCli, so you may have to look at the man page or web site to see if it can perform the tasks you need.
|
Its not a question about MegaCLi but how to make while loop run parallel.
I read about xargs tool which can be helpful but not sure about it. |
Thanks for the update and solution.
|
But still I need to see how to run the while loop in parallel.
Any idea? |
If MegaCLi can preform the tasks in parallel, then simply pass the name of all drives to it instead of using the loop.
|
A General way of adding newly added drives to the existing RAID is shown below:
Code:
While I put it into script it looks like as shown below: Code:
echo $drives | while IFS=" :" read _ _ slot _ status; do if [[ $status != "Online, Spun Up" ]]; then aslot=${slot:}; `$MegaCli -LDRecon -Start -r$raidlevel -Add -PhysDrv[$ENCLOSURE:$aslot] -l0 -a0` ; fi; done Code:
[root@localhost ~]# ./raidconfig.sh drives Then it chooses slot 12 and then it completes it before moving to 6, next 7 and so on.. |
So what I understand then, is that MegaCli cannot perform the task in parallel. Are you certain that if you call the command on more than one disk at a time that this is ok? ie. You do not
need to add them one at a time? If so you could try pushing each call into the background using '&' but I would probably confirm first that this is good practice and will not cause any potential issues. There is also a tool called 'parallel' which you might look into as another alternative (with the same caveat as above) |
Thanks for the response.
I read the manual and found that we can pass multiple enclosure:slot combination as shown below: Code:
MegaCli -LDRecon -Start -r5 -Add -PhysDrv[32:3, 32:4, 32:5] -l0 -a0 Code:
echo "$drives" | while IFS=" :" read -r _ _ slot _ status; do if [[ $status != "Online, Spun Up" ]]; then slot=$slot+${,$ENCLOSURE:$slot}; fi; done ./newraidconfig.sh: line 109: $slot+${,$ENCLOSURE:$slot%}: bad substitution Invalid input at or near token -l Exit Code: 0x01 I suspect slot=$slot+${,$ENCLOSURE:$slot%}; is incorrect. Any idea? |
Yes it is, but you would have to explain what you are trying to do as none of that makes any sense.
Maybe you could also show me what is in the variable 'drives' as I am not sure what the passed in data looks like? On a personal note, I am also not a fan of using the single line for what is a complicated while loop ... to me it just looks a bit cluttered |
All times are GMT -5. The time now is 04:03 PM. |