Thursday, January 30, 2014

awk sub, system, and getline to variable example

This is an example of having awk with system and getline calls... This is similar what debsums -c is doing but you can actually supply a custom md5sum list...
while read line; do echo $line | awk '{ x=$1; $1=""; sub("^ ", "/", $0); z=$0; sub("^", "\"", $0); sub("$", "\"", $0); if (system("[ -f " $0 " ]") == 0) { cmd="md5sum " $0 " | cut -d\  -f1"; cmd | getline y; close(cmd); if (y != x) printf "%-73s FAILED\n", z; } else printf "%-71s NOTFOUND\n", z;}'; done < /var/lib/dpkg/info/libc-bin.md5sums