To guess what's happening with some KDE applications doing weird things, I created a one line command to have a list of all files that are not located by a desktop application when I just launch and close it.
I use strace
output as source of data to be processed, as lines below:
openat(AT_FDCWD, "/usr/share/nvidia/nvidia-application-profiles-rc", O_RDONLY) = -1 ENOENT (No existe el fichero o el directorio)
openat(AT_FDCWD, "/usr/X11R6/lib/X11/fonts/.uuid", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No existe el fichero o el directorio)
openat(AT_FDCWD, "/var/cache/fontconfig/0bcde688-f6c6-45d7-9a5c-9a93ce4e186f-x86_64.cache-7", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No existe el fichero o el directorio)
openat(AT_FDCWD, "/usr/lib64/qt5/plugins/platformthemes/KDEPlasmaPlatformTheme.so.avx2", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No existe el fichero o el directorio)
openat(AT_FDCWD, "/etc/nvidia/nvidia-application-profiles-rc", O_RDONLY) = -1 ENOENT (No existe el fichero o el directorio)
I want to get a list of all not found files/folders in a text row and I got it with:
strace **DAN** 2>&1 | awk -v FS="," '/openat/ && /No existe/ {print substr($2, 3, length($2) - 3)} ' | sort | uniq -u | awk 'BEGIN{FS="/"; ORS=" "} {print $NF}'
where DAN is a desktop application name as "kate", "libreoffice" or anyone.
Note: /No existe/ is like /Doesn't exist/ or /Not found/
I'm sure that this command could be simplified, avoiding two "awk" commands, but don't know how. I use "sort" and "uniq" cause I don't want repeated filenames.
Anyone could simplify this?
Thank you in advance
CodePudding user response:
I kind of like your implementation as it's easy to understand. Doing this entirely in awk (or gawk in this case) would get a little muddy. Something like:
gawk -v FS="[,\"]" '/openat/ && /No existe/ {paths[gensub(/.*\//, "", 1, $3)]=1} END{PROCINFO["sorted_in"]="@ind_str_asc";for(path in paths){printf("%s ",path)};print}'
Essentially this is just dumping out the application name into the key of an associative array. This allows us to dedup since you can't have two keys with the same index.
Once the strace output is fully parsed we tell gawk to sort the array using its key, sorting by string (lexicographically), and in ascending order.
Then we iterate over the array and print out the key.
Like I said though, if I were writing this to be a supportable application, I would go with your implementation. The steps are clear in the processing and there isn't any funny business, like borrowing the deduping of associated array keys to mimic your uniq
as an example.
CodePudding user response:
Assuming your file names do not contain double quotes and the only double quotes in the matching lines are around the file name, you could use the double quotes as field separator, rework $2
and use the result as the key of an associative array (for the uniqueness):
$ strace **DAN** 2>&1 | awk -F'"' '
/^openat.*No existe/ {sub(/(.*\/)?/,"",$2); f[$2]}
END {for(k in f) print k}'
.uuid
0bcde688-f6c6-45d7-9a5c-9a93ce4e186f-x86_64.cache-7
nvidia-application-profiles-rc
KDEPlasmaPlatformTheme.so.avx2