psychosb
Technical User
- Oct 19, 2011
- 3
Hello to all!
I would like some help...
I'm trying to use AWK to filter the results of the file /proc/mdstat in linux.
The content of the file is:
[root@hostname~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdq1[0] sdr1[1]
264960 blocks [2/2] [UU]
bitmap: 0/33 pages [0KB], 4KB chunk
md1 : active raid1 sdq2[0] sdr2[1]
142793664 blocks [2/2] [UU]
bitmap: 2/137 pages [8KB], 512KB chunk
I'm trying to create a script that runs the following command:
/sbin/mdadm -Q --detail /dev/mdX
Where the "X" is the number of devices listed on the mdstat file.
I wrote the following script, and it's working fine...
But I'm wondering if there's any way that i can do the same thing, without using the pipe to run the second awk (awk 'NR=='$a -> to get the line number).
for ((a=1; a <= 10 ; a++))
do
mdx=`awk '$1 ~ /^[md]/ {print substr($0,0,3)}' /proc/mdstat | awk 'NR=='$a`
if [[ -n "$mdx" ]] ; then
/sbin/mdadm -Q --detail /dev/$mdx
else
echo
fi
done
I've made a lot of tests trying to use the awk to invoke the system command but without any success.
Does anyone have a idea?
Thanks!
I would like some help...
I'm trying to use AWK to filter the results of the file /proc/mdstat in linux.
The content of the file is:
[root@hostname~]# cat /proc/mdstat
Personalities : [raid1]
md0 : active raid1 sdq1[0] sdr1[1]
264960 blocks [2/2] [UU]
bitmap: 0/33 pages [0KB], 4KB chunk
md1 : active raid1 sdq2[0] sdr2[1]
142793664 blocks [2/2] [UU]
bitmap: 2/137 pages [8KB], 512KB chunk
I'm trying to create a script that runs the following command:
/sbin/mdadm -Q --detail /dev/mdX
Where the "X" is the number of devices listed on the mdstat file.
I wrote the following script, and it's working fine...
But I'm wondering if there's any way that i can do the same thing, without using the pipe to run the second awk (awk 'NR=='$a -> to get the line number).
for ((a=1; a <= 10 ; a++))
do
mdx=`awk '$1 ~ /^[md]/ {print substr($0,0,3)}' /proc/mdstat | awk 'NR=='$a`
if [[ -n "$mdx" ]] ; then
/sbin/mdadm -Q --detail /dev/$mdx
else
echo
fi
done
I've made a lot of tests trying to use the awk to invoke the system command but without any success.
Does anyone have a idea?
Thanks!