Programming and Scripting :: Can't go interactive after telnet logon script! ??



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.

What session terminates? the terminal window?

You could add a ' &' to the end of whatever you executed to load it in the background

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.

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.

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.

Next Page...
original here.