How to merge Expect script inside shell script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to merge Expect script inside shell script?
# 1  
Old 03-26-2015
How to merge Expect script inside shell script?

Hi I have two scripts one is Expect and other is shell.

I want to merge Expect code in to Shell script so that i can run it using only one script. Can somebody help me out ?

Order to execute: Run Expect_install.sh first and then when installation completes run runTests.sh shell script.



Expect_install.sh

Code:
#!/usr/bin/expect
set ViPR_HOSTNAME [lindex $argv 0]
set timeout 300

cd /root/cli-build
system "rm -rf /opt/storageos/cli/*"

sleep 5
system "wget https://$ViPR_HOSTNAME:4443/cli --no-check-certificate --content-disposition"
sleep 5
system "tar -xvf ViPR-cli.tar.gz"
sleep 5
spawn "python" "setup.py" "install"
sleep 5
expect "Installation Directory " { send " \r" }
sleep 5
expect "ViPR host " { send "$ViPR_HOSTNAME\r" }
sleep 5
expect "ViPR port " { send " \r" }
sleep 300
system "rm -rf /root/cli-build/ViPR-cli.tar.gz"
interact


runTests.sh


Code:
#!/bin/sh

echo $1
export PATH=$PATH:/opt/apache-maven-2.2.1/bin
export M2_HOME=/opt/apache-maven-2.2.1
sed -i s/VIPR_HOSTNAME=\.\*/VIPR_HOSTNAME=$1/g /opt/storageos/cli/viprcli.profile
source /opt/storageos/cli/viprcli.profile
/opt/apache-maven-2.2.1/bin/mvn clean
/opt/apache-maven-2.2.1/bin/mvn test
exit 0

Here while executing both the script takes same argument i.e. IP address.
# 2  
Old 03-26-2015
You cannot 'have' 2 different script languages within 1 file to execute.
However, you can start the expect script from your shell script, but not otherwise..

So you can start the expect script passing the internal variables from the shell script.

Hope this helps
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Capture run time of python script executed inside shell script

I have bash shell script which is internally calling python script.I would like to know how long python is taking to execute.I am not allowed to do changes in python script.Please note i need to know execution time of python script which is getting executed inside shell .I need to store execution... (2 Replies)
Discussion started by: Adfire
2 Replies

2. Shell Programming and Scripting

Expect not working inside my Bash script

I am trying to execute expect command inside by small bash script to login into servers using key authentication method. My script is as follows: #!/bin/bash HOST=$1 /usr/bin/expect -c " spawn ssh -i /root/.ssh/id_rsa root@$HOST expect -exact "Enter... (3 Replies)
Discussion started by: John Wilson
3 Replies

3. Programming

Calling another expect script inside an expect script

I have an expect script called remote that I want to call from inside my expect script called sudoers.push, here is the code that is causing me issues: set REMOTE "/root/scripts/remote" ... log_user 1 send_user "Executing remote script as $user...\n" send_user "Command to execute is: $REMOTE... (1 Reply)
Discussion started by: brettski
1 Replies

4. Shell Programming and Scripting

expect script inside shell script not working.

Shell Scipt: temp.sh su - <$username> expect pass.exp Expect script: pass.exp #!/usr/bin/expect -f # Login ####################### expect "Password: " send "<$password>\r" it comes up with Password: but doesnt take password passed throguh file. (2 Replies)
Discussion started by: bhavesh.sapra
2 Replies

5. Programming

Calling expect script inside another expect

Hi, Am very new to expect scripting.. Can You please suggest me how to call an expect script inside another expect script.. I tried with spawn /usr/bin/ksh send "expect main.exp\r" expect $root_prompt and spawn /usr/bin/ksh send "main.exp\r" expect $root_prompt Both... (1 Reply)
Discussion started by: Priya Amaresh
1 Replies

6. Shell Programming and Scripting

Passing username and password to a script running inside "expect" script

Hi I'm trying to run a script " abc.sh" which triggers "use.sh" . abc.sh is nothing but a "expect" script which provides username and password automatically to the use.sh script. Please find below the scripts: #abc.sh #!/usr/bin/expect -f exec /root/use.sh expect "*name*" send... (1 Reply)
Discussion started by: baddykam
1 Replies

7. Shell Programming and Scripting

Can i use if else inside expect command in shell script?

hii,, I am trying to automate jira. during my scripting using bash script, in the terminal i got the terminal message like this: "Configure which ports JIRA will use. JIRA requires two TCP ports that are not being used by any other applications on this machine. The HTTP port is where you... (1 Reply)
Discussion started by: nithinfluent
1 Replies

8. Programming

Expect script to run a Shell script on remote server

Hi All, I am using a expect script to run a shell script on remote server, the code is as follows. But the problem is that it executes only first command, and hangs it doesn't run the next commands. spawn ssh $uid@$host expect "password:" send "$password\r" expect "*\r" send... (2 Replies)
Discussion started by: yashwanthsn
2 Replies

9. Shell Programming and Scripting

how to read line inside expect script

hi, i have an existing ftp script that needs to be translated to SFTP so i have to use expect script to automate the login to the remote server. Now im facing with a problem becaise i have at least 50 files to be renamed ont he remote server. It's a hassle to hardcode every single command... (1 Reply)
Discussion started by: The One
1 Replies

10. Shell Programming and Scripting

how to run shell script inside expect script?

I have the code like this : shell script continues ... .... expect -c" spawn telnet $ip expect "login:" send \"$usrname\r\" expect "Password:" send \"$passwd\r\" expect "*\>" send \"$cmdstr\r\" ... (1 Reply)
Discussion started by: robbiezr
1 Replies
Login or Register to Ask a Question