Solved

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

Posted on 2006-06-10
3
3,237 Views
Last Modified: 2008-02-26
i need to send "test" regularly with a cronjob to 192.168.1.99:8000

currently the only solution i found was sheduling this script:
#!/bin/bash
echo "test" | netcat 192.168.1.99 8000 &
NETCATPID=$!
sleep 1
kill -s SIGINT $NETCATPID

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?

thanks,
robert

0
Comment
Question by:robert_skywalker
3 Comments
 
LVL 34

Assisted Solution

by:Duncan Roe
Duncan Roe earned 200 total points
ID: 16879326
You could do what you want with "expect" http://sourceforge.net/projects/expect
Instead of using netcat, you would telnet 192.168.1.99 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)
0
 
LVL 51

Expert Comment

by:ahoffmann
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?
0
 
LVL 5

Accepted Solution

by:
devrick0 earned 300 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)
Example:
./connect.py 192.168.1.99 8000

#/usr/bin/python
import socket, sys

def try_conn_tcp():
        try:
                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"
                sys.exit(1)
        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
                sys.exit(1)
        host = sys.argv[1]
        textport = sys.argv[2]
        port = int(textport)
        try_conn_tcp()
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

863 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now