LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 08-03-2012, 05:15 AM   #1
techyn
LQ Newbie
 
Registered: Aug 2012
Posts: 2

Rep: Reputation: Disabled
Unhappy 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
 
Old 08-03-2012, 05:29 AM   #2
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
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.
 
1 members found this post helpful.
Old 08-03-2012, 06:03 AM   #3
techyn
LQ Newbie
 
Registered: Aug 2012
Posts: 2

Original Poster
Rep: Reputation: Disabled
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.
 
Old 08-03-2012, 09:13 AM   #4
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
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
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Expect script: how do i send function key F12 in an expect script alix123 Programming 4 09-01-2013 10:06 PM
Issue in running commands in expect script from shell script yadvinder Programming 0 05-31-2012 05:07 AM
running shell script within expect script xombboxer Linux - Newbie 2 05-01-2011 01:42 PM
Can expect return control of a spawned process to a shell script? duffrecords Programming 4 04-28-2010 03:33 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration