The man page is ambiguously worded:
-f file Log the specified file.
There's one example in the man page with no further explanation:
logger -p local0.notice -t HOSTIDM -f /dev/idmc
POSIX is no help:
The logger utility saves a message, in an unspecified manner and format, containing the string operands provided by the user. The messages are expected to be evaluated later by personnel performing system administration tasks.
I would expect it to log:
- to the file
- something about the file
- or something from the file
However, if I do the following:
$ echo "contents" > testfile
$ logger -f ./testfile "test message"
$ cat testfile
contents
$ tail /var/log/messages
Aug 4 10:00:00 hostname logger: test message
I get nothing having to do with "testfile" or its contents nor are its contents changed. If testfile
doesn't exist before I issue the logger
command I get this error message:
logger: ./testfile: No such file or directory.
What is logger -f
supposed to do?
Best Answer
The GNU documentation is a little clearer and provided a hint for further testing:
It turns out that specifying a message overrides the specification of a file.
So this works:
and logs the contents of the file to the logfile. If the file consists of multiple lines, each line becomes a separate entry in the log.