A expect script with multiple shell statements

Spike

I am using fabric, which is a deployment tool only working in Python2.*, to deploy my blog to the remote server.

However my blog is written with Python 3.5, so I am trying to use expect script and pyenv tool to automatically do the deployment thing:

#!/usr/bin/expect
set timeout 10

spawn pyenv global system # changes python to 2.* version
spawn fab build  # gets files zipped

spawn fab deploy
expect "private key:"
send "x\r"
expect "Login password for 'myblog': "
send "*******\r"
expect eof

spawn pyenv global 3.5.1 # changes back

Then I found only spawn pyenv global system and spawn fab deploy part work.

Is this because the spawn fab build part doesn't need any input or feedback? But if so, it can't explain why the first statement spawn pyenv global system functioned. Also, weirdly, the last statement failed.

By the way, It's good when I run these four statements separately in commandline.

Spike

I tried add expect eof after every single statement and it works:

#!/usr/bin/expect
set timeout 10

spawn pyenv global system
expect eof

spawn fab build 
expect eof

spawn fab deploy
expect "key:"
send "x\r"
expect "password"
send "*******\r"
expect eof

spawn pyenv global 3.5.1
expect eof

Maybe when you want to execute a command that needs no input like ls -a, you add the expect eof after it

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How to get the exit code of spawned process in expect shell script?

Automate SCP with multiple files with expect script

How to pass argument in Expect through the command line in a shell script

Multiple statements in if else statement in shell scripting

Multiple shell script workers

chai-as-promised: multiple expect statements in a single test

Shell script: if multiple conditions

Difference between quoting variables in shell script "if" statements?

How to pass the argument in expect shell script during runtime

If, elif and else shell script Linux statements

Passing values that the commands in a shell script are going to expect

How to use TWO "for statements" in a shell script?

Nested If Statements in Shell Script

Expect script to run shell command

shell script crashes during if statements?

Multiple If statements in a bash script

How to make an expect script to expect either of multiple texts

How to execute command under if statement in Shell Script under expect condition?

Expect script embedded in shell: how to specify value defined in remote shell?

Linux shell: my `expect` script doesn't work as expected

shell script expect and spawn commands

Transforming IF statements to FOR or WHILE (Shell Script)

Illegal Characters in Password in Expect / Shell Script

Calling bash shell script from expect script fails : "no such file or directory"

Expect script to give multiple inputs

Entering multiple lines / statements into the IDLE shell?

AWK script with multiple statements not working on txt file

shell script with multiple variables

Running multiple expect/TCL code inside same shell script