Networking Forums

Networking Forums > Computer Networking > Linux Networking > Bash script via inetd = no joy

Reply
Thread Tools Display Modes

Bash script via inetd = no joy

 
 
tylernt
Guest
Posts: n/a

 
      08-29-2003, 06:10 PM
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.

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"
 
Reply With Quote
 
 
 
 
Barry Margolin
Guest
Posts: n/a

 
      08-29-2003, 07:03 PM
In article <(E-Mail Removed) >,
tylernt <(E-Mail Removed)> wrote:
>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.


In the TELNET protocol, newline is represented using the two-byte sequence
CR LF. But your script is just sending LF, because that's what Unix uses
to represent newline. The telnet client is just sending what it received
to the terminal.

>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?


You could pipe all the output through a sed command that adds \r at the end
of each line.

--
Barry Margolin, (E-Mail Removed)
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
 
Reply With Quote
 
laura fairhead
Guest
Posts: n/a

 
      08-29-2003, 08:03 PM
On 29 Aug 2003 11:10:53 -0700, (E-Mail Removed) (tylernt) wrote:

>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.
>
>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?


I would fiddle with the terminal settings, for example when you
do a 'stty -a' is the 'onlcr' setting enabled ?

If not then a simple "stty onlcr" might be what you need.

You can find out about what is going on with the input and
check for a hidden CR with something like;

echo "$myinput" |od -txCa

If there is a problem on the input as well you may want
to do another 'stty' this time adjusting an input setting.


byefrom
l


--
echo (E-Mail Removed) |sed 's/\(.\)\(.\)/\2\1/g'
 
Reply With Quote
 
Ian Fitchet
Guest
Posts: n/a

 
      08-29-2003, 08:08 PM
Barry Margolin <(E-Mail Removed)> writes:

> Stty only works if stdout is a terminal. When his script is run from
> inetd, stdout is a network socket.


You're right, of course, Barry.

Foolish boy, Pike!

Cheers,

Ian
 
Reply With Quote
 
laura fairhead
Guest
Posts: n/a

 
      08-29-2003, 08:49 PM
On Fri, 29 Aug 2003 19:44:00 GMT, Barry Margolin <(E-Mail Removed)> wrote:

>In article <(E-Mail Removed)>,
>Ian Fitchet <(E-Mail Removed)> wrote:
>>Barry Margolin <(E-Mail Removed)> writes:
>>
>>> You could pipe all the output through a sed command that adds \r at the end
>>> of each line.

>>
>> You could throw a quick
>>
>>stty onlcr
>>
>> into the top of your script.

>
>Stty only works if stdout is a terminal. When his script is run from
>inetd, stdout is a network socket.


I don't think this is true although to be sure I'm not up on all off the
intricacies of terminals and NVT's in UNIX yet (interesting subject ,
but the fact is that stdout is a pty (psuedo-terminal device ) when I use
telnet- as such why can't that (terminal) device support the ioctl
interface? Just testing using 'putty' on windows to connect to a linux box
(telnetd) I find that setting onlcr on/off has the desired effect.

>
>--
>Barry Margolin, (E-Mail Removed)
>Level(3), Woburn, MA
>*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
>Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.



byefornow
l


--
echo (E-Mail Removed) |sed 's/\(.\)\(.\)/\2\1/g'
 
Reply With Quote
 
Barry Margolin
Guest
Posts: n/a

 
      08-29-2003, 09:14 PM
In article <(E-Mail Removed)>,
laura fairhead <(E-Mail Removed)> wrote:
>On Fri, 29 Aug 2003 19:44:00 GMT, Barry Margolin
><(E-Mail Removed)> wrote:
>>Stty only works if stdout is a terminal. When his script is run from
>>inetd, stdout is a network socket.

>
>I don't think this is true although to be sure I'm not up on all off the
>intricacies of terminals and NVT's in UNIX yet (interesting subject ,
>but the fact is that stdout is a pty (psuedo-terminal device ) when I use
>telnet- as such why can't that (terminal) device support the ioctl
>interface? Just testing using 'putty' on windows to connect to a linux box
>(telnetd) I find that setting onlcr on/off has the desired effect.


When you do a normal telnet, it's telnetd, not inetd, that sets up the pty.
But if you run an ordinary program (regardless of whether it's a script or
binary) via inetd, its stdin/stdout/stderr will be connected directly to
the socket. There's no pty unless the program that inetd invokes
explicitly sets it up.

It would certainly be nice if there were an easy way to insert an NVT
filter in the data path. But it's not AFAIK. So it's the responsibility
of the server application to ensure that it performs appropriate input and
output translation.

--
Barry Margolin, (E-Mail Removed)
Level(3), Woburn, MA
*** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
 
Reply With Quote
 
/dev/rob0
Guest
Posts: n/a

 
      08-30-2003, 02:38 PM
In article <(E-Mail Removed)>, laura fairhead wrote:
> Well I think your sed filter method is probably the best idea then


Why not just "echo -e '\r'" after each line?
--
/dev/rob0 - preferred_email=i$((28*28+28))@softhome.net
or put "not-spam" or "/dev/rob0" in Subject header to reply
 
Reply With Quote
 
Ian Fitchet
Guest
Posts: n/a

 
      08-30-2003, 02:48 PM
Barry Margolin <(E-Mail Removed)> writes:

> You could pipe all the output through a sed command that adds \r at the end
> of each line.


How do people feel about this?

#! /bin/bash

exec > >(sed -e 's/$/FOO/')

echo hello
echo hello


Where I guess `FOO' is inappropriate in this case.

Cheers,

Ian
 
Reply With Quote
 
Dan Mercer
Guest
Posts: n/a

 
      08-30-2003, 03:18 PM

"tylernt" <(E-Mail Removed)> wrote in message news:(E-Mail Removed) om...
: 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
(E-Mail Removed)


:
: 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"


 
Reply With Quote
 
Chris Thompson
Guest
Posts: n/a

 
      09-05-2003, 08:34 PM
In article <42O3b.503$(E-Mail Removed)>,
Barry Margolin <(E-Mail Removed)> wrote:
[...]
>Stty only works if stdout is a terminal. When his script is run from
>inetd, stdout is a network socket.


<nitpick> stdin, not stdout </nitpick>

At least, in the implementations of stty(1) I am familiar with.

Chris Thompson
Email: cet1 [at] cam.ac.uk
 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Copy files using filenames from text files with shell script or bash script altariamx2003@gmail.com Linux Networking 4 11-23-2006 08:27 AM
Linux bash syntax Q: Coenraad Loubser Linux Networking 4 01-16-2005 05:31 PM
zmienna bash Zenon Linux Networking 1 05-07-2004 11:21 AM
Setting $TERM when using rsh and ssh with bash waterbottleboodle Linux Networking 1 11-08-2003 10:29 PM
Bash script to see if PPP link is up... Gabriel Michael Linux Networking 34 09-14-2003 03:55 PM



1 2 3 4 5 6 7 8 9 10 11