LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-24-2008, 09:15 PM   #1
john.daker
Member
 
Registered: Jul 2008
Posts: 33

Rep: Reputation: 15
How to call expect in shell script?


If I use #!/bin/expect,it works
Code:
#!usr/bin/expect  -f
set password my_passwd
spawn ssh my_user@my_ssh_server
expect "*password: "
send "$password\r"
interact
But when I use expect in shell script,it doesnt work
Code:
#!/bin/bash


/usr/bin/expect <<EOF
set password my_passwd
spawn ssh my_user@my_ssh_server
expect "*password: "
send "$password\r"
interact
EOF
How to use expect in shell script?
Thanks.
 
Old 08-24-2008, 09:27 PM   #2
matthewg42
Senior Member
 
Registered: Oct 2003
Location: UK
Distribution: Kubuntu 12.10 (using awesome wm though)
Posts: 3,530

Rep: Reputation: 65
Consider putting the expect script in a separate file and invoking it with the -f option.
 
Old 08-25-2008, 08:33 PM   #3
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Doesn't work is not a correct error description.

Put this in the expect part of you script:
Code:
exp_internal 1

Then execute you script with
Code:
sh -x yourscript
You should see something which leads you quickly to the problem. If not you are able to tell us where it goes wrong.

jlinkels
 
  


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
exec the expect command in a shell script wanghao Linux - Networking 6 11-23-2007 11:06 PM
How to combine Expect and Shell script Uday123 Programming 0 12-27-2005 09:01 AM
Shell Script call API treotan Programming 1 08-22-2005 10:59 PM
call a c program in a shell script jagman Programming 4 04-05-2005 04:58 PM
Call a shell script from php? jharper101 Programming 2 02-15-2005 12:51 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:54 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
Open Source Consulting | Domain Registration