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