LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-17-2008, 06:20 AM   #1
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Rep: Reputation: 39
Question Bash Shell Trying to use 'netcat' and 'mkfifio'? Or Whats the best way


Hi All,
I've set-up a netcat tcp connection from one computer to another... main reason is to find out if a connection is ever dropping as it appears to sometimes and this is causing some problems for some other software i run. Anyway... what i want to do is to have some kind of pipe straight into the netcat

The best way i've been able to do this so far is:-
mkfifo test123
tail -f test123 | netcat -l -p 1234

and then to just `echo blah > test123` in a while looped script

But is that the best way... i think probably not although it works.... i'm just being curious... i just don't like the tail -f i'm having to do whether thats the best way or not?

What i do currently is have a large file with a load of numbers.. equating to 3 days worth of constant connection. with netcat -i 60 -l -p 12345. What i'd prefer is (real time) `date` to be sent down the connection so if it does go i get an exact date when the last successful transmission was made.

Cheers All
MJ

Last edited by helptonewbie; 11-17-2008 at 07:02 AM.
 
Old 11-17-2008, 07:36 AM   #2
yowi
Member
 
Registered: Dec 2002
Location: Au
Distribution: Debian
Posts: 209

Rep: Reputation: 55
why not just leave a ping running and dump it's output to a file? A dash of awk and you'll know when it was down, how long it was down for, etc.
 
Old 11-17-2008, 10:16 AM   #3
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Original Poster
Rep: Reputation: 39
Hi,
Thanks for the reply... two reasons i'm not using ping is that ... i'm already running it .. it doesn't detect any problems as yet but i know there might be, but to fast for ping to notice a problem and plenty enough of a problem that a connection is dropped.

And two, because its a constant connection i'm trying to imitate ping isn't as such a constant open connection with a stream of data its more of a 'ping' :-o hehe

Cheers,
MJ
 
Old 11-17-2008, 04:38 PM   #4
yowi
Member
 
Registered: Dec 2002
Location: Au
Distribution: Debian
Posts: 209

Rep: Reputation: 55
TCP/IP is more robust than you give it credit for.
Test how tolerant it is by setting up the tests across your lan and then unplug an ethernet cable for a second or two. Keep increasing the unplug time until your "connection" is eventually broken.
With ping you'll see the round-trip times increase until the connection is eventually broken (ie packet errors) and you'll easily see when and for how the long the problem existed.

The packet network concept of a connection is not a good analogy to the physical world of water pipes or electrical connections. A packet network connection is a pair of programs listening and writing to sockets, with packets of data arriving sporadically and with "gaps" between each, the programs have no perception of how the packets got from A to B, how long it took or what happened on the way, they only receive an error if the TCP/IP layer fails to get a response within the time-out period.

Have a look at the output of "netstat -i", if you're seeing lots of TX and/or RX errors for the relevant interface then you know there's something wrong with your network.
 
Old 11-17-2008, 08:13 PM   #5
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
Related to your original post, you can use cat instead of tail because cat will block while waiting for input from the pipe as long as the writing end is open. I'm actually surprised that tail works.
ta0kira
 
Old 11-19-2008, 09:08 AM   #6
helptonewbie
Member
 
Registered: Aug 2006
Location: England Somewhere
Distribution: Mandriva, PCLinuxOS, Karoshi, Suse, Redhat, Ubuntu
Posts: 518

Original Poster
Rep: Reputation: 39
Thanks Guys, useful info. I know TCP is robust but it will tell me if the NIC has some kind of a small failure and drops any current connections, and that i will be able to see with a netcat, i could see it with a ping possibly as well. But i could also happen so fast that a ping won't pick-up on the problem. So anyway i'm using both already so i'm covered from all angles.

ta0kira - Thanks for the reply and yes it is working but i will change it to using cat, with your re-marks.. i think i did try before but the only thing i could get to work was tail -f..... but i'll give it another go anyway at some point.

Cheers All,
MJ
 
  


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
shell versus bash, whats the difference? mayaabboud Linux - Newbie 5 12-21-2007 06:21 AM
Obtain a windows shell from linux using netcat idefinehell Linux - Networking 5 08-04-2006 11:25 AM
Using Netcat through shell script zael Programming 1 05-22-2004 10:31 AM
netcat shell script didi Programming 3 03-17-2004 10:27 AM
Whats the difference Linux Console and BASH Shell glenn69 Linux - Newbie 2 08-31-2003 03:19 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:59 AM.

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