[BusyBox] scriptable telnet

Paul Fox pgf at brightstareng.com
Thu Nov 18 17:10:03 UTC 2004


 >  I am actually using busybox on a Sharp Zaurus PDA, and i had trouble
 > getting expect installed on it.  I am trying to telnet to a daemon running
 > on the PDA to continuously get some information from it, the daemon 
 > only support the telnet protocol. It doesn't require any login stufff, i just 
 > need to telnet to it, and run a few command and save its output to a file.
 > Is there any other ways to do it beside expect? I guess now i will wait
 > for Rob's netcat and see what happens.  

with some telnet programs you can do something like this:

    (
     sleep 2
     echo username
     sleep 2
     echo somepassword
     sleep 2
     echo date
     sleep 2
    ) | telnet somehost > session.log

there's no error checking, and no synchronization.  but for a
quick and dirty solution it can be handy.  

this doesn't work in busybox because busybox telnet exits if stdion
is not a terminal.  the following patch (only quickly tested)
makes this work.

paul

--- busybox-1.00.orig/networking/telnet.c	2004-09-14 13:24:58.000000000 -0400
+++ busybox-1.00/networking/telnet.c	2004-11-18 12:06:30.000000000 -0500
@@ -101,6 +101,7 @@
 	short	iaclen; /* could even use byte */
 	struct termios termios_def;
 	struct termios termios_raw;
+	char	do_termios;
 } G;
 
 #define xUSE_GLOBALVAR_PTR /* xUSE... -> don't use :D (makes smaller code) */
@@ -616,12 +617,12 @@
 
 static void rawmode(void)
 {
-	tcsetattr(0, TCSADRAIN, &G.termios_raw);
+	if (G.do_termios) tcsetattr(0, TCSADRAIN, &G.termios_raw);
 }
 
 static void cookmode(void)
 {
-	tcsetattr(0, TCSADRAIN, &G.termios_def);
+	if (G.do_termios) tcsetattr(0, TCSADRAIN, &G.termios_def);
 }
 
 extern int telnet_main(int argc, char** argv)
@@ -649,11 +650,12 @@
 
 	memset(&G, 0, sizeof G);
 
-	if (tcgetattr(0, &G.termios_def) < 0)
-		exit(1);
+	if (tcgetattr(0, &G.termios_def) >= 0) {
+		G.do_termios = 1;
 
-	G.termios_raw = G.termios_def;
-	cfmakeraw(&G.termios_raw);
+		G.termios_raw = G.termios_def;
+		cfmakeraw(&G.termios_raw);
+	}
 
 	if (argc < 2)
 		bb_show_usage();

=---------------------
 paul fox, pgf at brightstareng.com



More information about the busybox mailing list