I have a syslog server listening on localhost:514 as UDP and would like to write messages to it on that port. (Using Ubuntu 14.04)
If I run either of these commands this from bash it prints the date every 2 seconds to syslog
# Using netcat while true; do sleep 2; date; done | nc -u localhost 514 # Using /dev/udp while true; do sleep 2; date; done > /dev/udp/localhost/514
Now just to test things I kill the syslog server then start it up a few seconds later.
While the syslog process is dead, the /dev/udp command every 2 seconds prints this to the console, so it recognizes that there is no localhost:514 for it to write to. Once syslog is back, these connection refused messages stop and it resumes writing the date to syslog. This is as expected.
date: write error: Connection refused
But the netcat command doesn't do this. While the syslog process is dead, it doesn't print any output to the console. And when syslog is back, it doesn't continue writing the date to syslog.
Why won't netcat continue writing to localhost:514 when syslog is restarted? How can I get netcat to behave the way /dev/udp does in this example?