LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Bash Shell Trying to use 'netcat' and 'mkfifio'? Or Whats the best way (https://www.linuxquestions.org/questions/programming-9/bash-shell-trying-to-use-netcat-and-mkfifio-or-whats-the-best-way-684018/)

helptonewbie 11-17-2008 06:20 AM

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

yowi 11-17-2008 07:36 AM

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.

helptonewbie 11-17-2008 10:16 AM

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

yowi 11-17-2008 04:38 PM

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.

ta0kira 11-17-2008 08:13 PM

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

helptonewbie 11-19-2008 09:08 AM

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


All times are GMT -5. The time now is 08:02 PM.