Send syslog messages using logger, bash and netcat command-line utilities.

Preliminary information

At first read RFC 3164 The BSD syslog Protocol and RFC 5424 The Syslog Protocol as these RFC documents are crucial to understand the behavior of the syslog protocol

At first, you need to know that message priority is calculated using formula (Facility * 8) + Severity, so user.notice is (1 * 8) + 5) which means 13 priority..

CodeFacility
kernel messages
1user-level messages
2mail system
3system daemons
4security/authorization messages
5messages generated internally by syslogd
6line printer subsystem
7network news subsystem
8UUCP subsystem
9clock daemon
10security/authorization messages
11FTP daemon
12NTP subsystem
13log audit
14log alert
15clock daemon (note 2)
16local use 0 (local0)
17local use 1 (local1)
18local use 2 (local2)
19local use 3 (local3)
20local use 4 (local4)
21local use 5 (local5)
22local use 6 (local6)
23local use 7 (local7)
CodeSeverity
Emergency: system is unusable
1Alert: action must be taken immediately
2Critical: critical conditions
3Error: error conditions
4Warning: warning conditions
5Notice: normal but significant condition
6Informational: informational messages
7Debug: debug-level messages

Sample message using RFC 3164 protocol format.

<13>Oct 28 01:16:01 desktop service: User milosz started export process

Sample message using RFC 5424 protocol format.

<13>1 2021-10-28T01:16:30.378594+02:00 desktop service - - [timeQuality tzKnown="1" isSynced="0"] User milosz started export process

logger

Send sample message using logger utility and RFC 3164 protocol format.

$ logger --udp --server localhost --port 514 --priority user.notice --tag service --rfc3164 "User $(whoami) started export process"
Oct 28 01:18:58 desktop service: User milosz started export process

Send sample message using logger utility and RFC 5424 protocol format.

$ logger --udp --server localhost --port 514 --priority user.notice --tag service --rfc5424 "User $(whoami) started export process"
Oct 28 01:19:02 desktop service User milosz started export process

bash

Send sample message using bash network redirection.

$ echo "Backup script started" > /dev/udp/localhost/514
Oct 28 01:27:36 Backup script started

netcat

Send sample message using netcat utility.

$ echo "<13>localhost.localdomain Backup script finished with success" | netcat -q 0 -u localhost 514
Oct 28 01:31:15 localhost.localdomain Backup script finished with success

Send sample message using netcat utility and here string.

$ netcat -q 0 -u localhost 514 <<< "Setup complete" 
Oct 28 01:33:40 Setup complete 
ko-fi