[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Any general way of logging output from utilities in Debian/Linux? ...




On 8/14/25 20:50, lbrtchx@tutamail.com wrote:

I need to log the output of utilities in a way that I always know its version, for which I have been using a file with lines of text, each line containing 5 fields with all you need:

<installation program>|<utility>|<version option>|<on which line>|<which string on that line>

texlive-extra-utils|pdfcrop|--version|1|3

pdftotext|pdftotext|-v|1|3

kate|kate|--version|1|2

yt-dlp|yt-dlp|--version|1|2

but I don't know how to inset the last (fifth) field into the awk part of the statement to get the version:

IFS=$(echo -en "\n\b"); _L_AR=($( echo "${_L}" | tr '|' '\n')); _L_ARL=${#_L_AR[@]}

if [[ ${_L_ARL} -eq 5 ]]; then

_UTIL="${_L_AR[1]}"

#

which "${_UTIL}"

"${_UTIL}" ${_L_AR[2]} 2>&1 | head -n ${_L_AR[3]}

# _V=${_L_AR[4]}; "${_UTIL}" ${_L_AR[2]} 2>&1 | head -n ${_L_AR[3]} | awk '{print $'${_V}'}' # can't get the version ..

else

echo "// __ \$_L: |${_L}|, \$_L_ARL: |$_L_ARL|"

fi

~

lbrtchx



Hello!

You can do it entirely in awk.

```

awk -F'|' '
{
        package = $1
        utility = $2
        version_opt = $3
        line = $4
        word = $5
        command = utility " " version_opt
        command | getline
        print "VERSION: " utility " " $0
        
}'
```


Reply to: