Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am writing a script which adds a hard disk to existing raid configuration. Here is how the script goes:
Code:
raidlevel=`$MegaCli -LDInfo -Lall -aALL | awk '/RAID Level/' | awk '{print $4}' | cut -c 9`
echo $raidlevel
drives=`$MegaCli -PDlist -aALL -NoLog | egrep 'Slot|state' | awk '/Slot/{if (x)print x;x="";}{x=(!x)?$0:x" -"$0;}END{print x;}' | sed 's/Firmware state://g'`
echo $drives
sleep 5
option="-r"
echo "You have chosen to add drives to RAID. Please wait.."
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
exit
fi
O/P:
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 ~]#
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:}
2. There is no use for `` when calling the command as you are not passing the output of the command to anything.
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
echo "$drives" | while IFS=" :" read -r _ _ slot _ status; do if [[ $status != "Online, Spun Up" ]]; then slot=${slot}; $MegaCli -LDRecon -Start -r"$raidlevel" -Add -PhysDrv[$ENCLOSURE:$slot] -l0 -a0 ; fi; done
exit
fi
But the problem now is the above script tried to reconstruct and rebuild the newly added disk one after another. If I have added two hard drive of 146GB it will take almost double the time to get it rebuilt.
Is there any way I can run it in parallel. Say, if I add two hard disk, both of them should start reconstructed parallel.
So thats the reason why I want to run this in parallel. As of now, the script chooses the first slot 4 then it runs it and completes it.
Then it chooses slot 12 and then it completes it before moving to 6, next 7 and so on..
Last edited by your_shadow03; 08-03-2015 at 10:26 PM.
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)
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.