0

I am trying to send text log files to my remote syslog server. I need to be able to take a file, and for each line in that file (newline as the separator), send that line via netcat to a remote syslog host. I don't want the whole file to be sent in one connection as it will show in syslog as one massive blob. Also, I need to be able to execute this from the command line. I can't create a script and execute it.

For example, this sends the whole file in one blob (not what I want):

cat somemultilinefile | nc -u -w 0 syslogip 514

I have tried awk with system() and xargs, but have not found a combination that works. Any ideas?

AdminBee
  • 21,637
  • 21
  • 47
  • 71
  • Does this answer your question? [Execute a command once per line of piped input?](https://unix.stackexchange.com/questions/7558/execute-a-command-once-per-line-of-piped-input) – thanasisp Nov 29 '20 at 00:43

1 Answers1

0

So I have found this works:

cat somemultilinefile | while read -r line; do echo "$line" | nc -w0 -u syslog_server 514 ; done

Seems that there should be a better way but this gets it done.

  • 1
    There is a better way, check the `rsyslog` module [RELP](https://www.rsyslog.com/doc/v8-stable/configuration/modules/omrelp.html). – Eduardo Trápani Nov 29 '20 at 01:52