Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (2) </ [1] 2 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Can't go interactive after telnet logon script! ??, Auto logon always closes at end of scrip< Next Oldest | Next Newest >
yiddea Offline





Group: Members
Posts: 9
Joined: Aug. 2006
Posted: Aug. 02 2006,20:46 QUOTE

I need to make an automatic partial logon for a telnet service for my users. I have used io redirects and some aTerm parameters to get it all to work except for one problem. The session always closes at the end of the script.

I have tried installing expect but there is some obscure bug blocking the libc6 package from installing and TCL depends on that.

I left a correlary message asking about installing expect also but, in fact, I would prefer if there were an easier way than installing a dozen debian packages to get this to work.

Very Frustrating.
Back to top
Profile PM 
^thehatsrule^ Offline





Group: Members
Posts: 3275
Joined: July 2006
Posted: Aug. 03 2006,05:49 QUOTE

What session terminates? the terminal window?

You could add a ' &' to the end of whatever you executed to load it in the background
Back to top
Profile PM 
clacker Offline





Group: Members
Posts: 570
Joined: June 2004
Posted: Aug. 03 2006,14:22 QUOTE

yiddea, I believe you can use the cat command to accomplish something close what you want.  I had some problems with my telnet prompts when I tried this, but by redirecting the output of telnet to stderr I could see the output:

make a file of your initial telnet commands called myscript

Use this command line to pipe the text from that script into telnet:

cat myscript - | telnet > /dev/stderr

cat concatenates (joins) two files and the hyphen takes input from the standard input (the keyboard).  Then the output of telnet gets redirected from stdout to stderr so it doesn't get caught by the cat - command.
Back to top
Profile PM 
yiddea Offline





Group: Members
Posts: 9
Joined: Aug. 2006
Posted: Aug. 03 2006,15:41 QUOTE

Thanks for responding so quickly.

I tried using '&' in the script but it is really moot anyway since the script is invoked from an icon on the desktop anyway so there is no need to preserve the launching bash session.

The script involves console redirection already. The methods I have tried have varied. cat does not work because I need to give the host time to prompt before the login is given so I have to use 'sleep' for the pauses. I adapted your methods to my script with the same result.

Script [bash]
{ echo open host
 sleep 1
 echo login
 sleep 1
 echo passwd
}

The adapted command line is ./Script - | telnet > /dev/stderr

From what I have been reading bash behaves precisely opposite from DOS batch commands which wait for all processed to close before terminating the batch job. Bash instead terminates the spawned processes when it reaches the end of the script. In such a case it won't matter if I background the launch of the telnet session or whatever convoluted spawn process I can come up with since the child processes will be killed when the script is completed.

I also tried putting a long pause at the end of the invocation hoping that while it was waiting the console would be allowed to interact with the telnet session but it does not work. I think the console goes to /dev/null until the port is returned at the end of the script.
Back to top
Profile PM 
clacker Offline





Group: Members
Posts: 570
Joined: June 2004
Posted: Aug. 03 2006,16:26 QUOTE

How about this then.  Say your bash script is called script.sh, can you do this?

Create your script and make it executable:
Code Sample
#!/bin/bash
echo open host
sleep 1
echo login
sleep 1
echo passwd

chmod 777 script.sh

( script.sh ; cat - ) | telnet > /dev/tty

Thinking more about it, tty might be a better device to redirect to than stderr.  This looked like it worked for me.
Back to top
Profile PM 
6 replies since Aug. 02 2006,20:46 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (2) </ [1] 2 >/
reply to topic new topic new poll
Quick Reply: Can't go interactive after telnet logon script! ??

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code