how to echo CTRL-C to netcat or stop netcat from expecting CTRL-C to terminate?

Posted on 2006-06-10
Medium Priority
Last Modified: 2008-02-26
i need to send "test" regularly with a cronjob to

currently the only solution i found was sheduling this script:
echo "test" | netcat 8000 &
sleep 1

it there a more beautiful solution to echo the ctrl-c directly after "test" ?
i also don't like the "sleep", which seems to be necessary
what if sending "test" takes longer?


Question by:robert_skywalker
LVL 35

Assisted Solution

by:Duncan Roe
Duncan Roe earned 600 total points
ID: 16879326
You could do what you want with "expect" http://sourceforge.net/projects/expect
Instead of using netcat, you would telnet 8000. If "test" gets a response, you could specifically wait for that response. Other wise wait fior a bit, send ^] to escape to telnet command processor, send q\r
Or just kill the telnet process (not so neat)
LVL 51

Expert Comment

ID: 16884447
> .. need to send "test" regularly
what is regulary?
should test be the URL-path or a part of the HTTP header? Is it HTTP anyway?

Accepted Solution

devrick0 earned 900 total points
ID: 16884968
I wrote something in python that checks a tcp host & port.  So if you throw this into a script, name it connect.py then you can run it like this:
./connect.py [host] [port]
(the usage statement will let you know if you don't have the correct number of arguments)
./connect.py 8000

import socket, sys

def try_conn_tcp():
                print "Attempting tcp connection on port %d" % (port)
                s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                s.connect((host, port))
                print "Connection to %s on port %d succeeded." % (host, port), "\n"
        except socket.error, e:
                print "\nTCP Socket Connection error : %s" % e, "\n"

if __name__=='__main__':
        usage = "\nUsage: connect.py [host] [port]\n"
        if len(sys.argv) < 3:
                print >> sys.stderr, usage
        host = sys.argv[1]
        textport = sys.argv[2]
        port = int(textport)

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
The video will let you know the exact process to import OST/PST files to the cloud based Office 365 mailboxes. Using Kernel Import PST to Office 365 tool, one can quickly import numerous OST/PST files to Office 365. Besides this, the tool also comes…

587 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question