Actually the warning occurs when gawk hits ## while(getline<f) ## as
seen below. I changed my test dir and file to "/etc" and "/etc/hosts"
to eliminate potential permissions issues in /proc/sys/:
$ cat readdir_test2.awk
#-- test code --
@load "readdir"
BEGIN{
d="/etc"
f=d"/hosts"
while(getline<f)
print $0
close(f)
}
#-- ---- ---- --
Run & output:
$ gawk -f readdir_test2.awk
gawk: readdir_test.awk:6: warning:\
dir_take_control_of: opendir/fdopendir failed: Not a directory
gawk: readdir_test.awk:6: warning:\
input parser `readdir' failed to open `/etc/hosts'
=># Static table lookup for hostnames.
=># See hosts(5) for details.
=>
=>
It does output the contents of the hosts file as (=>) indicated.
Basically my goal is to use the "readdir" functionality to obtain the
paths to particular files which are then read in and processed. I found
additionally loading "readfile" provides a warning-free work-around:
$ cat readdir_test3.awk
#-- test code --
@load "readfile"
@load "readdir"
BEGIN{
d="/etc/"
f=d"hosts"
FS="/"
while(getline<d)
if($2~/[A-Z]/ && $3=="d")
print d$2
close(d)
str=readfile(f)
split(str,arr,"\n")
for(i in arr)
print arr[i]
}
#-- ---- ---- --
Run & output:
$ gawk -f readdir_test3.awk
/etc/ODBCDataSources
/etc/R
/etc/X11
# Static table lookup for hostnames.
# See hosts(5) for details.
This seems an okay solution if the files to be processes aren't huge;
it would be better to only read as much as needed from the files.
I'm wondering it there is a way to UNload a dynamic library once one is
done with it, something like ## @unload "readdir" ## ? Might be useful.
-J