我编写了这个 shell 脚本来将 ASM 设备映射到 AIX 机器上的物理设备。但是,我得到的输出不是预期的,并且无法调试它。我请求你的帮助。详情如下。
ASM 设备:
test160 orainfra +ASM1 >> ls -l /dev | grep orainfra
crw-rw-r-- 1 orainfra dba 34, 35 Jan 23 01:16 ebs_arch_31
crw-rw-r-- 1 orainfra dba 34, 36 Jan 23 01:16 ebs_arch_32
crw-rw-r-- 1 orainfra dba 34, 37 Jan 23 01:15 ebs_arch_33
crw-rw-r-- 1 orainfra dba 34, 38 Jan 23 01:16 ebs_arch_34
crw-rw-r-- 1 orainfra dba 34, 39 Jan 22 20:01 ebs_data1_31
crw-rw-r-- 1 orainfra dba 34, 40 Jan 23 19:39 ebs_data1_32
crw-rw-r-- 1 orainfra dba 34, 41 Jan 10 19:39 ebs_data1_33
crw-rw-r-- 1 orainfra dba 34, 42 Dec 25 02:22 ebs_data1_34
crw-rw-r-- 1 orainfra dba 34, 43 Jan 24 07:34 ebs_data1_35
crw-rw-r-- 1 orainfra dba 34, 44 Jan 25 07:41 ebs_data1_36
crw-rw-r-- 1 orainfra dba 34, 45 Jan 25 19:44 ebs_data1_37
crw-rw-r-- 1 orainfra dba 34, 46 Jan 1 19:49 ebs_data1_38
crw-rw-r-- 1 orainfra dba 34, 47 Jan 22 09:23 ebs_data1_39
crw-rw-r-- 1 orainfra dba 34, 48 Jan 15 07:01 ebs_data1_40
crw-rw-r-- 1 orainfra dba 34, 49 Jan 23 07:54 ebs_data1_41
crw-rw-r-- 1 orainfra dba 34, 50 Jan 22 09:13 ebs_data1_42
crw-rw-r-- 1 orainfra dba 34, 51 Jan 22 09:13 ebs_data1_43
crw-rw-r-- 1 orainfra dba 34, 10 Jun 17 2019 ebs_gg_data31
crw-rw-r-- 1 orainfra dba 34, 11 Jun 17 2019 ebs_gg_data32
crw-rw-r-- 1 orainfra dba 34, 12 Oct 21 16:20 ebs_gg_data33
crw-rw-r-- 1 orainfra dba 34, 13 Oct 21 16:19 ebs_gg_data34
crw-rw-r-- 1 orainfra dba 34, 5 Jun 17 2019 ebs_ocr11
crw-rw-r-- 1 orainfra dba 34, 6 Jun 17 2019 ebs_ocr12
crw-rw-r-- 1 orainfra dba 34, 52 Jul 23 2019 ebs_redoa_35
crw-rw-r-- 1 orainfra dba 34, 53 Jan 25 22:28 ebs_redoa_36
crw-rw-r-- 1 orainfra dba 34, 54 Jan 25 22:28 ebs_redoa_37
crw-rw-r-- 1 orainfra dba 34, 55 Jan 23 01:15 ebs_redoa_38
crw-rw-r-- 1 orainfra dba 34, 56 Jul 12 2019 ebs_temp_35
crw-rw-r-- 1 orainfra dba 34, 57 Jan 22 09:13 ebs_temp_36
crw-rw-r-- 1 orainfra dba 34, 58 Oct 21 18:23 ebs_temp_37
crw-rw-r-- 1 orainfra dba 34, 59 Jan 22 09:13 ebs_temp_38
crw-rw-r-- 1 orainfra dba 34, 7 Jan 26 05:25 ebs_voting11
crw-rw-r-- 1 orainfra dba 34, 8 Jan 26 02:02 ebs_voting12
crw-rw-r-- 1 orainfra dba 34, 9 Jun 17 2019 ebs_voting13
test160 orainfra +ASM1 >>
物理设备:
test160 orainfra +ASM1 >> ls -l /dev | grep rhdiskpower
crw-rw---- 1 root system 34, 0 Jun 17 2019 rhdiskpower0
crw-rw---- 1 root system 34, 1 Jun 17 2019 rhdiskpower1
crw-rw---- 1 root system 34, 10 Jun 17 2019 rhdiskpower10
crw-rw---- 1 root system 34, 11 Jun 17 2019 rhdiskpower11
crw-rw---- 1 root system 34, 12 Jun 17 2019 rhdiskpower12
crw-rw---- 1 root system 34, 13 Jun 17 2019 rhdiskpower13
crw-rw---- 1 root system 34, 2 Jun 17 2019 rhdiskpower2
crw-rw---- 1 root system 34, 3 Jun 17 2019 rhdiskpower3
crw-rw---- 1 root system 34, 34 Jul 10 2019 rhdiskpower34
crw-rw---- 1 root system 34, 35 Jul 10 2019 rhdiskpower35
crw-rw---- 1 root system 34, 36 Jul 10 2019 rhdiskpower36
crw-rw---- 1 root system 34, 37 Jul 10 2019 rhdiskpower37
crw-rw---- 1 root system 34, 38 Jul 10 2019 rhdiskpower38
crw-rw---- 1 root system 34, 39 Jul 10 2019 rhdiskpower39
crw-rw---- 1 root system 34, 4 Jun 17 2019 rhdiskpower4
crw-rw---- 1 root system 34, 40 Jul 10 2019 rhdiskpower40
crw-rw---- 1 root system 34, 41 Jul 10 2019 rhdiskpower41
crw-rw---- 1 root system 34, 42 Jul 10 2019 rhdiskpower42
crw-rw---- 1 root system 34, 43 Jul 10 2019 rhdiskpower43
crw-rw---- 1 root system 34, 44 Jul 10 2019 rhdiskpower44
crw-rw---- 1 root system 34, 45 Jul 10 2019 rhdiskpower45
crw-rw---- 1 root system 34, 46 Jul 10 2019 rhdiskpower46
crw-rw---- 1 root system 34, 47 Jul 10 2019 rhdiskpower47
crw-rw---- 1 root system 34, 48 Jul 10 2019 rhdiskpower48
crw-rw---- 1 root system 34, 49 Jul 10 2019 rhdiskpower49
crw-rw---- 1 root system 34, 5 Jun 17 2019 rhdiskpower5
crw-rw---- 1 root system 34, 50 Jul 10 2019 rhdiskpower50
crw-rw---- 1 root system 34, 51 Jul 10 2019 rhdiskpower51
crw-rw---- 1 root system 34, 52 Jul 10 2019 rhdiskpower52
crw-rw---- 1 root system 34, 53 Jul 10 2019 rhdiskpower53
crw-rw---- 1 root system 34, 54 Jul 10 2019 rhdiskpower54
crw-rw---- 1 root system 34, 55 Jul 10 2019 rhdiskpower55
crw-rw---- 1 root system 34, 56 Jul 10 2019 rhdiskpower56
crw-rw---- 1 root system 34, 57 Jul 10 2019 rhdiskpower57
crw-rw---- 1 root system 34, 58 Jul 10 2019 rhdiskpower58
crw-rw---- 1 root system 34, 59 Jul 10 2019 rhdiskpower59
crw-rw---- 1 root system 34, 6 Jun 17 2019 rhdiskpower6
crw-rw---- 1 root system 34, 7 Jun 17 2019 rhdiskpower7
crw-rw---- 1 root system 34, 8 Jun 17 2019 rhdiskpower8
crw-rw---- 1 root system 34, 9 Jun 17 2019 rhdiskpower9
test160 orainfra +ASM1 >>
脚本:
ls -l /dev | grep orainfra > /home/orainfra/TEST/asm_disks_8.lst
input_file="/home/orainfra/TEST/asm_disks_8.lst"
while IFS= read -r line
do
major=`echo "$line" | awk '{ print $5 }'`
minor=`echo "$line" | awk '{ print $6 }'`
asm_disk=`echo "$line" | awk '{ print $10 }'`
physical_disk=`ls -l /dev | grep rhdiskpower | grep "$major *$minor" | awk '{ print $10 }'`
echo "The ASM disk: '$asm_disk' is mapped to PHYSICAL Disk: '$physical_disk' " >> asm_physical_disks_mapping_8.lst
done <"$input_file"
输出:
The ASM disk: 'ebs_arch_31' is mapped to PHYSICAL Disk: 'rhdiskpower35'
The ASM disk: 'ebs_arch_32' is mapped to PHYSICAL Disk: 'rhdiskpower36'
The ASM disk: 'ebs_arch_33' is mapped to PHYSICAL Disk: 'rhdiskpower37'
The ASM disk: 'ebs_arch_34' is mapped to PHYSICAL Disk: 'rhdiskpower38'
The ASM disk: 'ebs_data1_31' is mapped to PHYSICAL Disk: 'rhdiskpower39'
The ASM disk: 'ebs_data1_32' is mapped to PHYSICAL Disk: 'rhdiskpower40'
The ASM disk: 'ebs_data1_33' is mapped to PHYSICAL Disk: 'rhdiskpower41'
The ASM disk: 'ebs_data1_34' is mapped to PHYSICAL Disk: 'rhdiskpower42'
The ASM disk: 'ebs_data1_35' is mapped to PHYSICAL Disk: 'rhdiskpower43'
The ASM disk: 'ebs_data1_36' is mapped to PHYSICAL Disk: 'rhdiskpower44'
The ASM disk: 'ebs_data1_37' is mapped to PHYSICAL Disk: 'rhdiskpower45'
The ASM disk: 'ebs_data1_38' is mapped to PHYSICAL Disk: 'rhdiskpower46'
The ASM disk: 'ebs_data1_39' is mapped to PHYSICAL Disk: 'rhdiskpower47'
The ASM disk: 'ebs_data1_40' is mapped to PHYSICAL Disk: 'rhdiskpower48'
The ASM disk: 'ebs_data1_41' is mapped to PHYSICAL Disk: 'rhdiskpower49'
The ASM disk: 'ebs_data1_42' is mapped to PHYSICAL Disk: 'rhdiskpower50'
The ASM disk: 'ebs_data1_43' is mapped to PHYSICAL Disk: 'rhdiskpower51'
The ASM disk: 'ebs_gg_data31' is mapped to PHYSICAL Disk: 'rhdiskpower10'
The ASM disk: 'ebs_gg_data32' is mapped to PHYSICAL Disk: 'rhdiskpower11'
The ASM disk: 'ebs_gg_data33' is mapped to PHYSICAL Disk: 'rhdiskpower12'
The ASM disk: 'ebs_gg_data34' is mapped to PHYSICAL Disk: 'rhdiskpower13'
The ASM disk: 'ebs_ocr11' is mapped to PHYSICAL Disk: 'rhdiskpower5
rhdiskpower50
rhdiskpower51
rhdiskpower52
rhdiskpower53
rhdiskpower54
rhdiskpower55
rhdiskpower56
rhdiskpower57
rhdiskpower58
rhdiskpower59'
The ASM disk: 'ebs_ocr12' is mapped to PHYSICAL Disk: 'rhdiskpower6'
The ASM disk: 'ebs_redoa_35' is mapped to PHYSICAL Disk: 'rhdiskpower52'
The ASM disk: 'ebs_redoa_36' is mapped to PHYSICAL Disk: 'rhdiskpower53'
The ASM disk: 'ebs_redoa_37' is mapped to PHYSICAL Disk: 'rhdiskpower54'
The ASM disk: 'ebs_redoa_38' is mapped to PHYSICAL Disk: 'rhdiskpower55'
The ASM disk: 'ebs_temp_35' is mapped to PHYSICAL Disk: 'rhdiskpower56'
The ASM disk: 'ebs_temp_36' is mapped to PHYSICAL Disk: 'rhdiskpower57'
The ASM disk: 'ebs_temp_37' is mapped to PHYSICAL Disk: 'rhdiskpower58'
The ASM disk: 'ebs_temp_38' is mapped to PHYSICAL Disk: 'rhdiskpower59'
The ASM disk: 'ebs_voting11' is mapped to PHYSICAL Disk: 'rhdiskpower7'
The ASM disk: 'ebs_voting12' is mapped to PHYSICAL Disk: 'rhdiskpower8'
The ASM disk: 'ebs_voting13' is mapped to PHYSICAL Disk: 'rhdiskpower9'
无法确定为什么在输出中捕获以下内容:
rhdiskpower50
rhdiskpower51
rhdiskpower52
rhdiskpower53
rhdiskpower54
rhdiskpower55
rhdiskpower56
rhdiskpower57
rhdiskpower58
rhdiskpower59
问候, RA
答案1
当脚本到达ebs_ocr11
变量时major="34,"
,minor="5". So the
grep 命令从列表中搜索正确的行将rhdiskpower
是:
... | grep rhdiskpower | grep rhdiskpower | grep rhdiskpower | grep rhdiskpower | grep rhdiskpower grep "34,*5" | awk ...
由于正则表达式没有指定$minor
变量后面应该有空格,因此该表达式不仅会匹配34, 5
,还会匹配34, 50
, 34, 51
... 一直到34, 59
。因此grep
将输出多行,并将awk
从每行中删除除第 10 个元素之外的所有元素,但会将它们保留为单独的行。
最终的值$physical_disk
是一个包含换行符的字符串:"rhdiskpower5\nrhdiskpower50\nrhdiskpower51\n..."
等等。
修复
我建议修改这一行:
physical_disk=`ls -l /dev | grep rhdiskpower | grep "$major *$minor" | awk '{ print $10 }'`
对此:
physical_disk=`ls -l /dev | grep "$major *$minor .* rhdiskpower[0-9]*$" | awk '{ print $10 }'`
这也删除了一个额外的grep
.
如果 AIXls
命令在其输出中使用制表符而不是空格,则您可能必须将正则表达式中的某些空格替换为\t
或类似的空格。
其他建议
ASM 磁盘名称应该很容易从磁盘本身读取。如果你看一下公开的描述ASM元数据块头和ASM 磁盘头紧随其后并计算偏移量,您会发现 ASM 磁盘相当容易识别:
- 在距 ASM 设备开头的偏移量 0x0020 处,应该有一个常量 string
ORCLDISK
。紧接着该字符串之后可能是特定于平台的驱动程序信息字符串,或者只是一个空终止符。 - 在偏移量 0x0048 处,您将找到 ASM 磁盘的名称,以 null 结尾。
- 在偏移 0x0068 处有磁盘当前所属的 ASM 磁盘组的名称,也是以 null 结尾。
- 在偏移 0x0088 处有磁盘所属的 ASM 故障组的名称,同样以 null 结尾。
如果您拥有 root 访问权限,并且有一个命令可以读取块设备上固定偏移处的字符串,那么有了这些信息,您就可以简单地循环遍历所有设备rhdiskpower*
,检查它们是否都是 ASM 磁盘,并读取标识信息如果是。这可能提供一种更强大的方法来映射 ASM 磁盘,而不是解析输出ls
。