Howto: Using syslog for a user-created shell script

Information abounds with syslog, but I cannot find something very succinct for my interest.

I have a user-created bash script that should log various debugging messages, information and error messages. I would like to use syslog. This is in the Ubuntu Server distribution.

I am only looking for a brief overview.

  • I see many files in /etc/logrotate.d that are not discussed on any manual pages that confuse me.
  • Do I have to register as a user? local0-7?
  • Do I need to do something to configure this before using them in a log command?
  • How to determine which logs are created? Or is it already done?

In answering these questions, I should be able to collect the details from the man pages.

+6
source share
2 answers

You need the logger (1) utility available in the bsdutils package.

On the man page:

  logger - a shell command interface to the syslog(3) system log module 

There is nothing significant to configure, just pass the switches you need. For instance.

 logger -p local3.info -t myprogram "What up, doc?" 

Now you can check where local3.info messages go, and you will see something like this:

 Jul 11 12:46:35 hostname myprogram: What up, doc? 

You only need to worry about logrotate if you need something more enjoyable than that.

Regarding the use of the log, I would use the daemon for the daemon messages and local for most other things. You should consult syslog (3) for various objects.

+10
source
  • Do not worry about logrotate. This does not affect you if you log into the system log.
  • You can use any tool that you like. See syslogd configuration for what ends there.
  • See the syslogd configuration for what ends there.
  • Look ... yes, you understand.
+1
source

Source: https://habr.com/ru/post/892464/


All Articles