문제

I have this awk script:

#!/usr/bin/awk -f
BEGIN {IGNORECASE=1} 
/nVidia/ {inner=1;pci=$1} 
/(corr|fatal)err\-/ {if (inner) print pci, $1, $2, $3, $4, $5, $6, $7} 
$0=="" {inner=0}

is there a syntax to always pipe sudo lspci -vvv to this script? I'm having to type sudo lspci -vvv|./checkpci each time I run the script. I know I could create a second script to launch the first script, but I think that is messy and would like to know the proper way to do so.

as an aside, I'm having some issues with my graphics card crashing and have seen the UncorrErr flag on some of the devices, does anyone have a reference as to what this means or how to troubleshoot further? right now I'm just going to run this script periodically to see when the errors show up in lspci to see if there is a time correlation.

도움이 되었습니까?

해결책

This should work for you:

#!/usr/bin/awk -f
BEGIN {
    IGNORECASE = 1
    cmd = "sudo lspci -vvv"
    while ((cmd | getline) > 0) {
        if ($0 ~ /nVidia/) {inner = 1; pci = $1} 
        if ($0 ~ /(corr|fatal)err\-/) {if (inner) print pci, $1, $2, $3, $4, $5, $6, $7} 
        if ($0 == "") {inner = 0}
    }
    close(cmd)
} 

다른 팁

I would change your awk script into a shell script:

#!/bin/sh
sudo lspci -vvv | /usr/bin/awk '
  BEGIN {IGNORECASE=1} 
  /nVidia/ {inner=1;pci=$1} 
  /(corr|fatal)err\-/ {if (inner) print pci, $1, $2, $3, $4, $5, $6, $7} 
  $0=="" {inner=0}
'
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top