Can't go interactive after telnet logon script! ??Forum: Programming and Scripting Topic: Can't go interactive after telnet logon script! ?? started by: yiddea Posted by yiddea on Aug. 02 2006,20:46
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. Posted by ^thehatsrule^ on Aug. 03 2006,05:49
What session terminates? the terminal window?You could add a ' &' to the end of whatever you executed to load it in the background Posted by clacker on Aug. 03 2006,14:22
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. Posted by yiddea on Aug. 03 2006,15:41
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. Posted by clacker on Aug. 03 2006,16:26
How about this then. Say your bash script is called script.sh, can you do this?Create your script and make it executable:
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. Posted by yiddea on Aug. 22 2006,19:47
This script is differently lacking. I'll give you that.When this script ends the shell does not close but no keystroke does anything and I cannot quit or break out of it short of manually closing the window. Not even killing the process works. Posted by clacker on Sep. 01 2006,13:55
how did you run the script? Did you use the ( script.sh ; cat - ) | telnet > /dev/tty command or did you just type script.sh? When I used the above command from an xerminal using the script.sh from my previous post it worked. |