tail file over tcp
I am trying to send changes of a file using 'tail' over a tcp port, but I can not find any references to do this. I have seen that you can do it to a serial port using
Code:
tail -f /path/to/cdr/file > /dev/ttyS0 |
I think it is something like this:
On the target computer enter: 5<>/dev/tcp/<host2>/port On the remote computer enter: tail -f file >/dev/tcp/<host1>/port -- You could pipe the output of tail to netcat: netcat -l <port> and on the other computer: tail -f file | /dev/tcp/<host1>/port See the "Advanced Bash Scripting Guide" on the www.tldb.org website and the manpage and readme for netcat. |
Thanks Jschiwal. The machine I am trying to send to is a windows machine listening on a port 4515. Am I correct is assuming that /dev/tcp/<host1>/port is the machine I am trying to send to?
|
Quote:
Code:
#!/bin/bash A laptop and a desktop. I'm at the laptop and ssh'd into the desktop because I was too lazy to walk over there! desktop: netcat -l -p 8080 laptop: sudo tail -f /var/log/messages >/dev/tcp/hpmedia/8080 root's password: Result at Desktop: May 14 12:35:10 hpamd64 SuSEfirewall2: batch committing... May 14 12:35:10 hpamd64 SuSEfirewall2: Firewall rules successfully set May 14 12:42:33 hpamd64 syslog-ng[2762]: STATS: dropped 0 May 14 12:46:08 hpamd64 sudo: jschiwal : TTY=pts/2 ; PWD=/home/jschiwal ; USER=root ; COMMAND=/usr/bin/tail -f /var/log/messages May 14 12:49:06 hpamd64 sudo: jschiwal : TTY=pts/2 ; PWD=/home/jschiwal ; USER=root ; COMMAND=/sbin/rcSuSEfirewall2 status You need the target to be listening or you will get: echo "This is a test" >/dev/tcp/hpamd64/8080 -bash: connect: Connection refused -bash: /dev/tcp/hpamd64/8080: Connection refused So Connection refused could just mean that there isn't a listener to complete the handshake, and isn't necessarily a firewall problem. |
Nearly there. The damn windoze machine is looking for either carriage return or Line feed and is therefore not seeing any thing until it gets one. Can we send this along with the tail?
|
Pipe the tail command through unix2dos to convert \n to \n\r.
Code:
sudo tail -f /var/log/messages | unix2dos >/dev/tcp/hpmedia/8080 |
All times are GMT -5. The time now is 04:11 AM. |