LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 05-13-2007, 06:45 PM   #1
lloydie-t
LQ Newbie
 
Registered: Mar 2006
Location: UK
Distribution: Redhat
Posts: 5

Rep: Reputation: 0
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
Can you help?
 
Old 05-13-2007, 07:31 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
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.
 
Old 05-13-2007, 08:05 PM   #3
lloydie-t
LQ Newbie
 
Registered: Mar 2006
Location: UK
Distribution: Redhat
Posts: 5

Original Poster
Rep: Reputation: 0
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?
 
Old 05-14-2007, 07:10 AM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Quote:
Originally Posted by lloydie-t
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?
Yes. The abs-guide has this example:
Code:
#!/bin/bash
# dev−tcp.sh: /dev/tcp redirection to check Internet connection.
# Script by Troy Engel.
# Used with permission.
TCP_HOST=www.dns−diy.com   # A known spam−friendly ISP.
TCP_PORT=80                # Port 80 is http.
# Try to connect. (Somewhat similar to a 'ping' . . .)
echo "HEAD / HTTP/1.0" >/dev/tcp/${TCP_HOST}/${TCP_PORT}
MYEXIT=$?
: <<EXPLANATION
If bash was compiled with −−enable−net−redirections, it has the capability of
using a special character device for both TCP and UDP redirections. These
redirections are used identically as STDIN/STDOUT/STDERR. The device entries
are 30,36 for /dev/tcp:
  mknod /dev/tcp c 30 36
I did this between two Linux machines:
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.

Last edited by jschiwal; 05-14-2007 at 07:11 AM.
 
Old 05-14-2007, 02:31 PM   #5
lloydie-t
LQ Newbie
 
Registered: Mar 2006
Location: UK
Distribution: Redhat
Posts: 5

Original Poster
Rep: Reputation: 0
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?
 
Old 05-15-2007, 02:18 AM   #6
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Pipe the tail command through unix2dos to convert \n to \n\r.

Code:
sudo tail -f /var/log/messages | unix2dos >/dev/tcp/hpmedia/8080
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl File::Tail hell whysyn Programming 2 03-14-2007 02:44 PM
I need to tail -f just a few colums o a text file ericcarlson Linux - General 3 01-30-2007 03:07 PM
scp/ssh tail(multiple file) remote copy tpreitano Linux - General 1 08-22-2005 02:17 PM
Tail Last Modified File in a Directory tyoungblood Linux - Software 3 08-12-2005 08:42 AM
dmegs tail Unchecked file sysytem -- Run e2fsck Nichole_knc Slackware 6 04-18-2004 05:10 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 04:50 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration