問題:コマンド変数の値は、li12[q]
独自の実際の内容として参照できません。
症状:コマンド変数valueを実際に引用すると、li12[q]
fatal:|
リダイレクトに使用される式に空の文字列値が含まれます。
メモ:
- ただし、コマンド変数には、以前のk5変数と同じ独自の値があります
li12[q]
。getline
li12[q]
コマンド変数名自体を引用できるため、構文と構造に問題はありません。
#
#
# lspci -v|grep -Ei "fib|scsi|raid|sas|net|ide|ata"|grep -i ^[0-9]|awk '{kin1[NR]=$1; prt[NR]="";for(ik=2;ik<=NF;ik++){prt[NR]=prt[NR]$ik" "}}END\
{while("ls -l /sys/class|grep -Ei \"scsi|sas|fc|net|ide|ata\"|grep -Eiv \"disk|tape|device|gen\""|getline){li11[++h1]=$9}; for(i=1;i<=NR;i++)\
{for(s=1;s<=h1;s++){h2=0;d3="(find /sys/class/"li11[s]" -type l -exec bash -c '\''echo s `ls -l {}`'\'' \\;|grep -i devices|grep -Ei \""kin1[i]"(/|$)\")\
2>/dev/null"; while(d3|getline){k5=li12[++h2]=$10$11$12; k6=h2}; for(q=1;q<=h2;q++){if(li12[q] ~/[a-zA-Z]/){ while("echo -e \"li12[q]\""|getline k7); k2=k7; k3=$1;\
if( q == h2 ){s=h1+1}; if(q>1){kin1[i]=prt[i]=""};printf " %-16s%-6s%-16s%-16s%-100s%-16s\n",kin1[i],k6,k5,k3,prt[i],k2}}}}}'
03:00.0 1 /sys/class/scsi_host/host0/device->../../../devices/pci0000:00/0000:00:02.2/0000:03:00.0/host0s RAID bus controller: Hewlett-Packard Company Smart Array Gen8 Controllers (rev 01) li12[q]
04:00.0 1 /sys/class/net/eth0/device->../../../devices/pci0000:00/0000:00:02.0/0000:04:00.0s Ethernet controller: Emulex Corporation OneConnect 10Gb NIC (be3) (rev 01) li12[q]
04:00.1 1 /sys/class/net/eth1/device->../../../devices/pci0000:00/0000:00:02.0/0000:04:00.1s Ethernet controller: Emulex Corporation OneConnect 10Gb NIC (be3) (rev 01) li12[q]
04:00.2 1 /sys/class/iscsi_host/host3/device->../../../devices/pci0000:00/0000:00:02.0/0000:04:00.2/host3s Mass storage controller: Emulex Corporation OneConnect 10Gb iSCSI Initiator (be3) (rev 01) li12[q]
04:00.3 1 /sys/class/iscsi_host/host4/device->../../../devices/pci0000:00/0000:00:02.0/0000:04:00.3/host4s Mass storage controller: Emulex Corporation OneConnect 10Gb iSCSI Initiator (be3) (rev 01) li12[q]
05:00.0 1 /sys/class/fc_host/host1/device->../../../devices/pci0000:00/0000:00:03.0/0000:05:00.0/host1s Fibre Channel: QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA (rev 02) li12[q]
05:00.1 1 /sys/class/fc_host/host2/device->../../../devices/pci0000:00/0000:00:03.0/0000:05:00.1/host2s Fibre Channel: QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA (rev 02) li12[q]
#
#
#
# lspci -v|grep -Ei "fib|scsi|raid|sas|net|ide|ata"|grep -i ^[0-9]|awk '{kin1[NR]=$1; prt[NR]="";for(ik=2;ik<=NF;ik++){prt[NR]=prt[NR]$ik" "}}END\
{while("ls -l /sys/class|grep -Ei \"scsi|sas|fc|net|ide|ata\"|grep -Eiv \"disk|tape|device|gen\""|getline){li11[++h1]=$9}; for(i=1;i<=NR;i++)\
{for(s=1;s<=h1;s++){h2=0;d3="(find /sys/class/"li11[s]" -type l -exec bash -c '\''echo s `ls -l {}`'\'' \\;|grep -i devices|grep -Ei \""kin1[i]"(/|$)\")\
2>/dev/null"; while(d3|getline){k5=li12[++h2]=$10$11$12; k6=h2}; for(q=1;q<=h2;q++){if(li12[q] ~/[a-zA-Z]/){ while("echo -e "li12[q]""|getline k7); k2=k7; k3=$1; \
if( q == h2 ){s=h1+1}; if(q>1){kin1[i]=prt[i]=""};printf " %-16s%-6s%-16s%-16s%-100s%-16s\n",kin1[i],k6,k5,k3,prt[i],k2}}}}}'
awk: cmd. line:3: (FILENAME=- FNR=7) fatal: expression for `|' redirection has null string value
#
#
編集以下は@glennjackmanによって提供されたより明確にフォーマットされた上記のコードです。
lspci -v \
| grep -Ei "fib|scsi|raid|sas|net|ide|ata" \
| grep -i ^[0-9] \
| awk '
{
kin1[NR] = $1
prt[NR] = ""
for (ik = 2; ik <= NF; ik++) {prt[NR] = prt[NR] $ik " "}
}
END {
while ("ls -l /sys/class | grep -Ei \"scsi|sas|fc|net|ide|ata\" | grep -Eiv \"disk|tape|device|gen\"" | getline) {
li11[++h1] = $9
}
for (i = 1; i <= NR;i++) {
for (s = 1; s <= h1;s++) {
h2 = 0
d3 = "(find /sys/class/"li11[s]" -type l -exec bash -c '\''echo s `ls -l {}`'\'' \\; | grep -i devices | grep -Ei \""kin1[i]"(/|$)\") 2>/dev/null"
while (d3 | getline){
k5 = li12[++h2] = $10 $11 $12
k6 = h2
}
for (q = 1; q <= h2;q++){
if (li12[q] ~/[a-zA-Z]/) {
while ("echo -e "li12[q]"" | getline k7)
k2 = k7
k3 = $1
if (q == h2) {s = h1+1}
if (q > 1) {kin1[i] = prt[i] = ""}
printf " %-16s%-6s%-16s%-16s%-100s%-16s\n", kin1[i], k6, k5, k3, prt[i], k2
}
}
}
}
}
'
RHEL 6.4システムで上記と同じawkスクリプトを使用すると、他の失敗の結果/進行が提供されます。
注:同じ空の文字列値に対して以前に失敗したすべての結果は、RHEL 5.8システムでのみ機能しました。
sh: ../../../devices/pci0000:00/0000:00:02.2/0000:03:00.0/host0: No such file or directory
03:00.0 1 /sys/class/scsi_host/host0/device->../../../devices/pci0000:00/0000:00:02.2/0000:03:00.0/host0s RAID bus controller: Hewlett-Packard Company Smart Array Gen8 Controllers (rev 01)
sh: ../../../devices/pci0000:00/0000:00:02.0/0000:04:00.0: No such file or directory
04:00.0 1 /sys/class/net/eth0/device->../../../devices/pci0000:00/0000:00:02.0/0000:04:00.0s Ethernet controller: Emulex Corporation OneConnect 10Gb NIC (be3) (rev 01)
sh: ../../../devices/pci0000:00/0000:00:02.0/0000:04:00.1: No such file or directory
04:00.1 1 /sys/class/net/eth1/device->../../../devices/pci0000:00/0000:00:02.0/0000:04:00.1s Ethernet controller: Emulex Corporation OneConnect 10Gb NIC (be3) (rev 01)
sh: ../../../devices/pci0000:00/0000:00:02.0/0000:04:00.2/host3: No such file or directory
04:00.2 1 /sys/class/iscsi_host/host3/device->../../../devices/pci0000:00/0000:00:02.0/0000:04:00.2/host3s Mass storage controller: Emulex Corporation OneConnect 10Gb iSCSI Initiator (be3) (rev 01)
sh: ../../../devices/pci0000:00/0000:00:02.0/0000:04:00.3/host4: No such file or directory
04:00.3 1 /sys/class/iscsi_host/host4/device->../../../devices/pci0000:00/0000:00:02.0/0000:04:00.3/host4s Mass storage controller: Emulex Corporation OneConnect 10Gb iSCSI Initiator (be3) (rev 01)
sh: ../../../devices/pci0000:00/0000:00:03.0/0000:05:00.0/host1: No such file or directory
05:00.0 1 /sys/class/fc_host/host1/device->../../../devices/pci0000:00/0000:00:03.0/0000:05:00.0/host1s Fibre Channel: QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA (rev 02)
sh: ../../../devices/pci0000:00/0000:00:03.0/0000:05:00.1/host2: No such file or directory
05:00.1 1 /sys/class/fc_host/host2/device->../../../devices/pci0000:00/0000:00:03.0/0000:05:00.1/host2s Fibre Channel: QLogic Corp. ISP2532-based 8Gb Fibre Channel to PCI Express HBA (rev 02)
答え1
空白は無料なので、一部を使用する必要があります。
これはあなたがすることですか?
lspci -v \
| grep -Ei "fib|scsi|raid|sas|net|ide|ata" \
| grep -i ^[0-9] \
| awk '
{
kin1[NR] = $1
prt[NR] = ""
for (ik = 2; ik <= NF; ik++) {prt[NR] = prt[NR] $ik " "}
}
END {
while ("ls -l /sys/class | grep -Ei \"scsi|sas|fc|net|ide|ata\" | grep -Eiv \"disk|tape|device|gen\"" | getline) {
li11[++h1] = $9
}
for (i = 1; i <= NR;i++) {
for (s = 1; s <= h1;s++) {
h2 = 0
d3 = "(find /sys/class/"li11[s]" -type l -exec bash -c '\''echo s `ls -l {}`'\'' \\; | grep -i devices | grep -Ei \""kin1[i]"(/|$)\") 2>/dev/null"
while (d3 | getline){
k5 = li12[++h2] = $10 $11 $12
k6 = h2
}
for (q = 1; q <= h2;q++){
if (li12[q] ~/[a-zA-Z]/) {
while ("echo -e "li12[q]"" | getline k7)
k2 = k7
k3 = $1
if (q == h2) {s = h1+1}
if (q > 1) {kin1[i] = prt[i] = ""}
printf " %-16s%-6s%-16s%-16s%-100s%-16s\n", kin1[i], k6, k5, k3, prt[i], k2
}
}
}
}
}
'
答え2
@rowboat あなたのすばらしい答えに感謝します。この答えをテストしたところ、うまくいきました!
次の文に置き換えます
。
while ("echo -e "li12[q]"" | getline k7)
到着する:
while (("echo -e "li12[q]"") | getline k7)