Problema: o valor da variável de comando de li12[q]
não pode ser referenciado como seu próprio conteúdo real.
Sintoma: Uma vez que eu realmente faço referência ao valor da variável de comando de li12[q]
, falhou com fatal: expressão para |
redirecionamento tem valor de string nulo.
Notas:
- Mas a variável de comando de
li12[q]
tem seu próprio valor, que é exatamente o mesmo que agetline
variável anterior de k5! - A sintaxe e a estrutura correspondentes não devem ter problemas, pois o
li12[q]
próprio nome da variável de comando pode ser referenciado.
#
#
# 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
#
#
EDIT aqui está o código acima formatado de forma muito mais legível, cortesia de @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
}
}
}
}
}
'
Agora há um resultado/progresso com falha diferente com o mesmo script awk acima no sistema RHEL 6.4.
Notas: Todos os resultados anteriores com falha sobre o mesmo valor de cadeia nula são executados apenas nos sistemas 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)
Os espaços em branco são gratuitos, você deve usar alguns.
É isso que você está fazendo?
@rowboat Muito obrigado por sua ótima resposta maravilhosa Eu já testei esta resposta e também foi executada com sucesso!
Apenas substitua apenas pela seguinte declaração:
from:
para :