LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
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 03-02-2007, 03:34 PM   #1
Paul77
LQ Newbie
 
Registered: Feb 2007
Posts: 12

Rep: Reputation: 0
Combined bash and expect script


Hi
can anyone inform if its possible to run an expect script followed by a bash
shell script from one script?

Rgds
Paul
 
Old 03-02-2007, 04:02 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Sure, no problem:

Code:
#!/bin/bash
# Run an expect script
/usr/local/bin/someExpectScript
# Run a bash script
/usr/local/bin/someBashScript
 
Old 03-02-2007, 04:13 PM   #3
Paul77
LQ Newbie
 
Registered: Feb 2007
Posts: 12

Original Poster
Rep: Reputation: 0
Hi
thanks for the reply but won't there need to be
a #!/usr/bin/expect line somewhere in the file?


rgds
Paul
 
Old 03-02-2007, 04:16 PM   #4
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
No. The expect script is '/usr/local/bin/someExpectScript' - that needs the '#!/usr/bin/expect' magic.
 
Old 03-05-2007, 05:07 AM   #5
Paul77
LQ Newbie
 
Registered: Feb 2007
Posts: 12

Original Poster
Rep: Reputation: 0
Hi

The following does not work - the log script completes but the setview does not.
If the setview is performed first then the log script is not run.

Rgds
Paul



#!/bin/bash

#run login script
log

cleartool setview pblades__view
 
Old 03-05-2007, 10:15 AM   #6
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Please post both scripts (in code blocks) so we can see what is happening.
 
Old 03-05-2007, 11:42 AM   #7
Paul77
LQ Newbie
 
Registered: Feb 2007
Posts: 12

Original Poster
Rep: Reputation: 0
ok here is a cat of the expect script and the bash script that calls it and
the output when the bash script is run


pb@dhcp-172#
p@dhcp-172#
pb@dhcp-172#
pb@dhcp-172#
pb@dhcp-172# cat lg
#!/usr/bin/expect

spawn ssh pb@smokey

# pb@smokey's password:
expect "password:" {
send "aaaaaaaa\r"
}

interact

pb@dhcp-172#
pb@dhcp-172#
pb@dhcp-172#
pb@dhcp-172#
pb@dhcp-172#
pb@dhcp-172# cat log
#!/bin/bash



#run login script
/u/pb/scripts/lg


cleartool setview pb__merge_to_1.1



pb@dhcp-172#
pb@dhcp-172#
pb@dhcp-172#
pb@dhcp-172#
pb@dhcp-172# log
spawn ssh pb@smokey
pb@smokey's password:
Last login: Mon Mar 5 16:22:42 2007 from dhcp-172
setting DISPLAY=dhcp-172:0
Linux Startup

Hello

pb@smokey#
pb@smokey#
pb@smokey#



=> the login script lg completes but the next line to set the view
is not run
 
Old 03-05-2007, 11:51 AM   #8
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
That's because of the 'interact'; the first script effectively never exits until the session ends.
 
Old 03-05-2007, 03:18 PM   #9
Paul77
LQ Newbie
 
Registered: Feb 2007
Posts: 12

Original Poster
Rep: Reputation: 0
If the setview is done first then the log script
should'nt both have worked?
 
Old 03-05-2007, 03:26 PM   #10
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
What is setview?

If you are going to paste again, please use a code block. It's hard to see the delineation between comments and code above. In the advanced reply text box, select your code and click on the "#" icon (when you hover over the icons they identify their function).
 
Old 03-08-2007, 09:10 AM   #11
Paul77
LQ Newbie
 
Registered: Feb 2007
Posts: 12

Original Poster
Rep: Reputation: 0
The setview line: cleartool setview <view>
sets the current view to a given view.

If its the first line in the scripts then the
expect login script is not carried out.

If the setview line is replaced with a pwd
then the expect script is carried out.

Any ideas why this and if there is a way of getting
round the problem?




Code:
#!/usr/bin/expect

spawn ssh pb@smokey

# pb@smokey's password:
expect "password:" {
send "aaaaaaaa\r"
}

interact





Code:
#!/bin/bash

cleartool setview pb__merge_to_1.1

#run login script
/u/pb/scripts/lg


Rgds
Paul
 
Old 03-08-2007, 09:17 AM   #12
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
Without seeing the close for "cleartool" I can tell you why it's not returning control.
 
  


Reply



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
Need help with BASH-scripts and EXPECT ElFredrico Linux - General 17 05-17-2012 11:51 PM
expect/bash sk8guitar Programming 5 10-06-2009 12:00 PM
Expect Script coolest Programming 7 02-16-2009 03:59 PM
Script... variables with expect? Manana Linux - Networking 1 01-19-2007 04:41 AM
Trouble calling 'expect' from bash raypen Linux - Software 1 06-01-2006 08:05 PM

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

All times are GMT -5. The time now is 07:40 PM.

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
Open Source Consulting | Domain Registration