LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   How to get the control back from expect script to a shell script? (https://www.linuxquestions.org/questions/linux-software-2/how-to-get-the-control-back-from-expect-script-to-a-shell-script-4175420144/)

techyn 08-03-2012 05:15 AM

How to get the control back from expect script to a shell script?
 
Hi,

I would like to brief the problem what I am trying and facing.

I've a shell script which is the master script
1. From the shell script, I am calling a expect script.
2. Inside the expect script I open a thread and ssh to a machine and trigger another python script.
3. Once the python script is executed completely the control is coming back to the expect script.

4. But the control from the expect script to shell script is not happening.

Looks like the thread we opened in the expect is not getting closed automatically as soon as the execution is done. It is hanging there & I've to manually give an "exit" in the prompt and then the control will come back to the shell script.

Please help to resolve the issue

zhjim 08-03-2012 05:29 AM

Just ideas no real solutions.
What about putting the exit inside the expect script itself? There is a option to have expect wait for a certain time before it continues. Might be an option.
Or you could have the pyhton script print out a "magic line" that you expect on and then exit.

techyn 08-03-2012 06:03 AM

Hi zhjim, Thanks for the reply.

I've tried passing the exit inside the script but it is not coming out still.

here is my piece of code.

#!/usr/bin/expect

spawn su - $acc
expect "Password:"
send "$pass\n"
expect {
">" { }
"$" { }
}

send "ssh -Y host\n"
expect "assword:"
send "$pass\n"
expect {
">" { }
"$" { }
}

send "cd some path\n"

expect {
">" { }
"$" { }
}

send "python.py commandline_arg1 commandline_arg2"

expect{
"*host*>" { }
}


send "exit\n"

interact


I am calling the above script from a shell script, after the completion of this script I am expecting the control to come back to shell script but it is not coming.. I've to pass a exit manually to close this thread.

zhjim 08-03-2012 09:13 AM

Does the expect script return when run on its own?

Also judging from the script I conclude that you want to run the script without putting in the password for the ssh connection. Did you thought about key log in for the ssh connection? Would make the use of expect obsolete. Take a look here if suiting http://www.debian-administration.org/articles/530


All times are GMT -5. The time now is 01:41 AM.