Results 1 to 4 of 4
I am new to script and learning .
I am palnning to get raid status by processing the file /proc/mdstat .
i have an out for cat /proc/mdadm
**************************
Personalities ...
- 07-28-2008 #1Just Joined!
- Join Date
- Jul 2008
- Posts
- 24
[SOLVED] get value in inside brackets .Scripting .
I am new to script and learning .
I am palnning to get raid status by processing the file /proc/mdstat .
i have an out for cat /proc/mdadm
**************************
Personalities : [raid1]
md1 : active raid1 hdc[2][F] hdd[1]
9920 block [2/1] [_U]
*************************
I am not interested in these details . I need from First line "raid1" . and
giving this as input another script should yield .
md1
If md1 is fed as a parameter to a new script ,it should give hdc , hdd along with their staus codes 2 and failed for hdc , 1 and success for hdd .
II can do only below
Script1 :
cat /proc/mdadm | grep Personalities | awk '{print $2}'
But i dont know how can i remove [ ] from [raid1]
scripts 2:
cat /proc/mdadm | grep raid1 | awk {print $1}'
script3 :
cat /proc/mdadm | grep raid1 |awk '{print $5}
i dont know how to get value 2 and F from hdc[2][F].
and also how many are left (like hdd , hde .hdf etc )
Please help with scripting .
I
- 07-28-2008 #2Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
Please don't waste processes by cat-ing a single file to grep
You have to careful how you arrange the square brackets inside the single-character position range regular expression.Code:grep Personalities /proc/mdadm | awk '{print $2}' | sed 's/[][]//g'
I'll leave you to try to get further with the rest of the script - ask again when you get stuck.
- 07-29-2008 #3Linux User
- Join Date
- May 2008
- Location
- NYC, moved from KS & MO
- Posts
- 251
Code:awk '/Personalities/ {print $3}' /proc/mdadm | tr -d []
- 07-29-2008 #4Just Joined!
- Join Date
- Jul 2008
- Posts
- 24
Your answer is super .
I found some other methods ,but its not a good solution .
I made use of OR (|) instead of brackets .
grep Personalities /proc/mdadm | awk '{print $2}' | sed 's/\[\|]//g'



