[prev in list] [next in list] [prev in thread] [next in thread] 

List:       hpux-admin
Subject:    [HPADM] SUMMARY: Redirecting into telnet
From:       johnmc () insync ! com
Date:       1995-09-29 16:43:22
[Download RAW message or body]

Wow!  This list is fantastic.  Thank you to the people who responded so
quickly (much more so than I summarized).

I have committed the ultimate sin.  In my haste to implement my favorite
solution, I erased the author's name and address.  Please accept my most
sincere appologies.  I would love for you to send me your name so I can
give you the credit you deserve.

================================================================================
=  My original post
================================================================================

Hello,

It has been requested that an MIS manager have the ability to display
messages on all terminals connected to DTC's whether the terminal is logged
in or not.  For those terminals logged in, it is simply a matter of catting
out to the device file created by ddfa.  For terminals not logged in, we
have the ability to telnet to the DTC specifying  some port generated by an
HP provided formula.

The problem lies in being able to redirect the message in from a file.    We
can telnet to the DTC port and type and the characters appear on the terminal.
But when I redirect the message and a break and quit sequence in from a file,
I only break and quit (See Below).  

How can I solve my problem?  Is it some telnet setting?

** COMMAND **
   telnet dtc01 20759 < message.txt

** BEGIN message.txt FILE **
   This is a message.
   ^]quit
** END message.txt FILE **

TIA,

John

================================================================================
=  My favorite response (Please give me a chance to redeem myself)
================================================================================
=  I do not know which compiler was used by the author to compile this, but
=  I had to move all the inline declarations to the beginning of the 
=  respective modules.
================================================================================

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>

int 
OpenSock(char *hostname, short port) {
    struct hostent *hp = gethostbyname(hostname);
    if (!hp) {
	perror("host unknown");
	return -1;
    }

    int s = socket(AF_INET, SOCK_STREAM, 0);
    if (s == -1) {
	perror("socket() failed");
	return -1;
    }

    struct sockaddr_in sin;
    sin.sin_family = AF_INET;
    sin.sin_port = port;
    memcpy(&sin.sin_addr, hp->h_addr, hp->h_length);

    if (connect(s, &sin, sizeof(sin)) == -1) {
	perror("connect failed");
	close(s);
	return -1;
    }
    return s;
}

int 
main(unsigned argc, char *argv[]) {
    if (argc != 3) {
	fprintf(stderr,"%s hostname portnumber\n",argv[0]);
	exit(1);
    }

    char *hostname = argv[1];
    short port = atoi(argv[2]);

    int sock = OpenSock(hostname,port);
    if (sock == -1)
	exit(1);

    char buf[8192];
    int c; 
    while (c = read(0,buf,sizeof(buf))) {
	int written;
	char *pend = buf + c;
	for (char *p = buf; p < pend; p += written) {
	    written = write(sock,p,pend-p);
	    if (written == -1) {
		perror("sock write failed");
		exit(1);
	    }
	}
    }
    return 0;
}


From: Alan Barclay <alan@elaine.drink.com>

Use expect. 

================================================================================

From: teffta@crypt.erie.ge.com (Andrew R. Tefft)

This is a use for expect. 

================================================================================

From: Anna Yaksich <aly@housing.qld.gov.au>

this is a bit crude, but it works for us:

( cat message_file ; echo "^]" ; echo quit ) | telnet $DESTINATION


hope this helps

-- Anna.

================================================================================

From: Chavdar Ivanov <ci@delcam.co.uk>

Use expect ( usual archive places ).

================================================================================

From: Steve Fosdick <stevef@aom.bt.co.uk>

I have experimented with this here, using the standard UNIX login port
for testing, and with a username and (wrong) password as the input file.

First I tried redirecting telnet's input from a file but without the
^[quit on the end.  This caused the username and password to be sent
before they were prompted for and hence the other end did not
recognise them.

Then I tried adding the ^[quit to the end of the file.  This time I
got no sign of a response at all.  Again I think this problem is
related to speed, and my guess is that one of the following is
happenning.

    1.  When the telnet command processes the quit command, the
	characters from the file are still in a transmit queue, and
	telnet closes the connection in such a way that they get
	fluished rather than waiting for them to transmit before the
	connection closes.

    2.  Perhaps the characters are being transmitted, but the telnet
	command closes the network connection before the echoed
	version arrives back from the other end.

For the next step I tried feeding the script to the telnet command
more slowly.  I wrote a little shell script called 'slow'

    #! /bin/sh

    while read line
    do
        sleep 1
        echo "$line"
    done

And used this to feed the script to the telnet command:

    slow < /tmp/tnscript | telnet host

this worked correctly, entering the username and password at the
correct prompt, waiting for the "login incorrect" message, then
closing the connection.

I also tried other options, like feeding the message to telnet at full
speed and then sleeping a bit at the end before sending the quit
command, however because of the way telnet reads and interprets its
input, this doesn't seem to work.

-- 
Steve Fosdick

================================================================================

From: Tapani Tarvainen <tt@math.jyu.fi>

Chances are it's simply that the text is being buffered
but the break takes effect immediately and flushes the buffer.
Try inserting a pause before the break, e.g.,

#!/bin/ksh
{
echo 'Message of the day follows:\n'
cat /etc/motd
echo '\nThat was it!'
sleep 5
echo '\035'
echo close
} | telnet dtc01

Works for me.

--
Tapani Tarvainen

--
johnmc@insync.com    |    John T. McCormick    |    Manager Product Development
in/sync DATA PRODUCTS, Inc. | 30 Executive Park | Ste 270 | Irvine, CA | 92714
-------------------------------------------------------------------------------
   The opinions expressed herein are those of the author, not of in/sync.

--
             ---> Please post QUESTIONS and SUMMARIES only!! <---
        To subscribe/unsubscribe to this list, contact majordomo@cv.ruu.nl
  Name: hpux-admin@cv.ruu.nl                 Owner: owner-hpux-admin@cv.ruu.nl
 Archive: (FTP & browse):        ftp.cv.ruu.nl/pub/digests/hpux-admin 
          (Web, browse, search): http://hpux.ced.tudelft.nl/HPUX_ADMIN_ARCHIVE

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic