Re: Bash script via inetd = no joy

From: Dan Mercer (dmercer_at_mn.rr.com)
Date: 08/30/03

  • Next message: Oliver Fox: "Help"
    Date: Sat, 30 Aug 2003 10:18:48 -0500
    
    

    "tylernt" <tylernt@yahoo.com> wrote in message news:f076244d.0308291010.61302341@posting.google.com...
    : Hello,
    :
    : I wrote a Bash script in Linux using 'read' and 'echo'. The script
    : works just fine from the console.
    :
    : However, when I put it in services and inetd.conf and then telnet in
    : to run it, I get a stairstep effect: after the script 'echo'es
    : something and then tries to 'read' something, the cursor is placed
    : below the last character printed from the 'echo' rather than in the
    : leftmost column. Like LF was issued but not CR. This occurs using both
    : the Win2k telnet client and from the Linux telnet client.

    The Win2k telnet client is a POS. You need to get a real telnet client,
    like the Cygwin client. That will allow you to set the modes by which
    telnet handles carriage returns.

        set crlf on # send cr as cr-lf
        set crmod on # handle received cr-lf sequence properly

    You can also add cr to the IFS string on a read so it is ignored:
    Assuming your bash is really bash2 (bash1 is obsolescent):

    cr=$'\r'

        IFS="${IFS}${cr}" read mydata

    Your linux telnet should already have the same capabilities as the cygwin
    telnet.

    Dan Mercer
    dmercer@mn.rr.com

    :
    : Also. If I 'echo' back the variable that I just 'read', it shows what
    : I typed in, but none of my 'if' statement logic recognizes the string
    : (perhaps because there is a hidden CR and/or LF attached?).
    :
    : It seems to be a CRLF thing... any idea how to run a Bash script that
    : uses 'echo' and 'read' via inetd? Or are there equivalent Bash
    : commands that are more CRLF friendly when run through inetd? Or can I
    : append some CR/LF codes to my 'echo'es and strip extra CR/LFs from my
    : 'read's somehow?
    :
    : And yes, I know this is a huge security hole but it's in a protected
    : test environemnt.
    :
    : Please help... Thanks in advance!! Here is the script:
    :
    : #!/bin/bash
    : echo "Greetings"
    : read myinput
    : until [ "$myinput" = "quit" ]
    : do
    : if [ "$myinput" = "data" ]; then
    : echo "Enter your data"
    : read mydata
    : until [ "$mydata" = "stop" ]
    : do
    : echo $mydata >> ~/output.txt
    : read mydata
    : done
    : echo "Data received"
    : else
    : echo "Unknown command"
    : fi
    : read myinput
    : done
    : echo "Goodbye"


  • Next message: Oliver Fox: "Help"

    Relevant Pages