Logging to the System Logger in Bash
Gregg
If you are writing a shell script and want any messages to appear in the system logger you can just use the logger command to do this.
Here is an example on my Slackware system:
$ logger -t TEST "This is a test message"$ cat /var/log/messagescat: /var/log/messages: Permission denied$ su -Password:# cat /var/log/messagesAug 23 17:44:47 slackbook TEST: This is a test message
You can also log to systemd by providing a parameter to logger:
logger --journald <<endMESSAGE_ID=67feb6ffbaf24c5cbec13c008dd72309MESSAGE=The dogs bark, but the caravan goes on.DOGS=barkCARAVAN=goes onend
or you can optionally provide a file whose contents will be logged:
logger --journald=entry.txt
See the logger manpage for additional information.