💾 Archived View for rawtext.club › ~zilog › 2024-02-11-znews.txt captured on 2024-03-21 at 16:58:35.
-=-=-=-=-=-=-
Sun 11 Feb 2024 05:27:33 AM UTC Those Gawk warning messages bothered me enough to keep at the search for a clean solution. Making use of the filefuncs(3am) library 'stat' function provided the fix. An example: print a list of users w/ readable ~/.wiki/ dirs: #!/usr/bin/gawk -E # wiki_users.awk -- prints users with readable wiki dirs @load "readdir" @load "filefuncs" BEGIN { FS = "/" ; H = "/home/" ; W = "/.wiki/" while (getline <H == 1) { PTH = H $2 W if (stat(PTH,st) == 0 && !ERRNO == 0) print $2 } close(H) } The 'stat(PTH,st) == 0' tests for existence, the '!ERRNO == 0' tests for readability. This was enough for the above case but if one wants to filter on a particular permissions mode the 'st' array generated contains a "pmode" index, set to a string value, i.e. "drwxr-x---". For those unfamiliar with the readdir(3am) library, if it's loaded then doing 'while(getline <dir == 1)' reads the contents of 'dir', returning a string of the form "file_inode/file_name/file_type" for each readable entry (presence of the last bit depends on filesystem support). Setting FS = "/" makes parsing the string easy. Anyway, as an excuse to apply the above methods I made a RTC who-is browser -- whodat -- which is in ~zilog/public_bin/ for anyone that cares to use it (the lynx(1) text browser is used as the front-end).