2016-08-23 63 views
-1

我正在寻找解决方案来为Linux创建Oracle ASM udev规则文件。我有两个输入文件。 file1具有ASM磁盘要求的信息,file2具有磁盘信息。从两个输入文件创建udev规则文件

例如,file1的第2行显示DATA12需要每个128G的3个磁盘(DATA12_01,DATA12_02,DATA12_03)。 file2具有大小的所有磁盘信息。从这两个输入文件我需要创建如下所示的输出文件。

猫文件1

Count - size - name 
3 - 128 GB DATA12 
1 - 128 GB TEMP02 
2 - 4 GB ARCH03 
2 - 1 GB ARCH04 
1 - 3 GB ORAC01 

猫文件2

UUID          Size 
360060e80166ef70000016ef700006700   128.00 GiB 
360060e80166ef70000016ef700006701   128.00 GiB 
360060e80166ef70000016ef700006702   128.00 GiB 
360060e80166ef70000016ef700006703   128.00 GiB 
360060e80166ef70000016ef700006730    4.00 GiB 
360060e80166ef70000016ef700006731    4.00 GiB 
360060e80166ef70000016ef700006733    1.00 GiB 
360060e80166ef70000016ef700006734    1.00 GiB 
360060e80166ef70000016ef700006735    3.00 GiB 

输出文件

ACTION=="add|change", ENV{DM_NAME}=="360060e80166ef70000016ef700006700", SYMLINK+="udevlinks/DATA12_01" 

ACTION=="add|change", ENV{DM_NAME}=="360060e80166ef70000016ef700006701", SYMLINK+="udevlinks/DATA12_02" 

ACTION=="add|change", ENV{DM_NAME}=="360060e80166ef70000016ef700006702", SYMLINK+="udevlinks/DATA12_03" 

ACTION=="add|change", ENV{DM_NAME}=="360060e80166ef70000016ef700006703", SYMLINK+="udevlinks/TEMP02_01" 

ACTION=="add|change", ENV{DM_NAME}=="360060e80166ef70000016ef700006730", SYMLINK+="udevlinks/ARCH03_01" 

ACTION=="add|change", ENV{DM_NAME}=="360060e80166ef70000016ef700006731", SYMLINK+="udevlinks/ARCH03_02" 

ACTION=="add|change", ENV{DM_NAME}=="360060e80166ef70000016ef700006733", SYMLINK+="udevlinks/ARCH04_01" 

ACTION=="add|change", ENV{DM_NAME}=="360060e80166ef70000016ef700006734", SYMLINK+="udevlinks/ARCH04_02" 

ACTION=="add|change", ENV{DM_NAME}=="360060e80166ef70000016ef700006735", SYMLINK+="udevlinks/ORAC01_01" 

回答

0

这是一个在AWK:

$ cat > test.awk 
BEGIN {FS="([.]| +)"} # field separator do deal with "." in file2 128.00 
FNR==1 {next}   # skip header 
NR==FNR {    # read available disks to pool from file1 
    for(i=1; i<=$1; i++) 
     a[$5"_"0i]=$3 # name and set the disks into pool 
    next} 
{ 
    for(i in a) {  # look for right sized disk 
     if(a[i]==$2) { # when found, print... 
      printf "%s%s%s%s%s", "ACTION==\"add|change\", ENV{DM_NAME}==\"",$1,"\",\"SYMLINK+=\"udevlinks/",i,"\"\n" 
      delete a[i] # ... and remove from pool 
      break 
     } 
    } # if no device was found: 
    old=len; len=length(a); if(old==len) {print "No device found for ",$0} 
} 
$ awk -f test.awk file1 file2 
ACTION=="add|change", ENV{DM_NAME}=="360060e80166ef70000016ef700006700","SYMLINK+="udevlinks/DATA12_01" 
ACTION=="add|change", ENV{DM_NAME}=="360060e80166ef70000016ef700006701","SYMLINK+="udevlinks/DATA12_02" 
... 
No device found for THIS_IS_AN_EXAMPLE_OF_MISSING_DISK   666.00 GiB 

由于磁盘搜索使用for(i in a)保证从磁盘读取磁盘的顺序。

+0

Awsome。大胆的解决方案。另外我试图在每个输出之前添加另一行“#uuid date”。我试图波纹管,它不工作。它也没有给出任何 错误。
d =“'date +%D'” printf“%s%s \ n”,“#\”“,$ 1,”\“d”
printf“%s%s%s%s% s“,”ACTION == \“add | change \”,ENV {DM_NAME} == \“”,$ 1,“\”,\“SYMLINK + = \”udevlinks /“,i,”\“\ n” 输出
#360060e801605a400000105a4000039ba
ACTION == “添加|变化”,ENV {} DM_NAME == “360060e801605a400000105a4000039ba”, “SYMLINK + =” udevlinks/DATA07_01 – Pavel

+0

经与HTML换行符问题 – Pavel

+0

请提供所需的输出的一个例子。 –