- #HOW TO USE TELNET IN SHELL SCRIPT BACKGROUND CODE#
- #HOW TO USE TELNET IN SHELL SCRIPT BACKGROUND PASSWORD#
#HOW TO USE TELNET IN SHELL SCRIPT BACKGROUND PASSWORD#
Screen -S abc-alpha-32 -p abc-alpha-32 -X stuff "expect /home/user12/scripts/master_dian.sh user_id password $(printf \\r)" Screen -S abc-alpha-32 -p abc-alpha-32 -X stuff "script -f /home/user12/scripts/abc-alpha-32.log $(printf \\r)"Įcho 'running expect command in session.' Using screen command to create a session that would run just as a user login session and below is a working copy of my script - #!/bin/bashĮcho 'running script command in session.' After banging my head and breaking walls around my cube, this is how I made it work. I don't have much details regarding this but this is one of the output from my experiments. I tried several ways to execute a shell script that logs the telnet output in the background, but later found the options are not possible because -ġ> When you try to execute a child script / command in a master script, even as a background process (using & at the end of the command), the child process will be terminated the moment the master script exits / terminates.Ģ> You may try to execute the master script forever or in an infinite loop (bad option :P), but the telnet session or channel cannot run as a background process as the OS kills the channel associated to the telnet session. Other alternative is to run each expect script one after the other, but to automate and to accommodate near future requests, these expect scripts have to run using a shell script.Īm not an expert in this matter and any help is greatly appreciated.Īlright. The whole purpose of this script is to run the expect scripts in the background that would collect logs until the processes are killed. Shell script - shell_script.sh #!/bin/bashĮxpect expect_script.sh user_id password > /var/logs/abc1.log &Įxpect expect_script.sh user_id password > /var/logs/abc1.log &Įxpect script - expect_script.sh #!/usr/bin/expect
Also - This is used for debugging only, won't be necessary in the delivered software.I'm trying to run multiple expect instances using a shell script in the background, but what actually happens is that the expect processes are killed when the shell script terminates even after running the shell script and expect scripts in the background.
#HOW TO USE TELNET IN SHELL SCRIPT BACKGROUND CODE#
It was written in sections by different code monkeys and I'm integrating. If you have ANY ideas, I'm willing to hear it.ĮDIT - Oh yeah, I didn't write the code to the processes that are actually running, so I don't know about what exactly everything is doing (as far as system calls and such). Sorry for the long post, but I wanted to explain it correctly.
My system: I'm running RHEL 5.1 and currently using the bash shell (but I am willing to write the script in a different shell if you think it will make a difference) Maybe there is a way to pass input to a command that is in the background? That would also solve my issue, but I don't think there is a way to do that either.
Basically the process I want to bring to the foreground allows us to enable some debugging. I am sure some of you are wondering why in the world would I do this, but to keep a long post from being a novel I left that out. It might be impossible, since it sounds like it could be a nice security flaw, but if it was possible it would be the best fit for my situation. Is it possible to bring this forward on this shell? Now I understand that the script starts a new shell so that is why when the script is completed that I cannot see the process in the background with jobs. tmp/new: line 11: fg: no job ~]$ jobs ~]$