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.
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.
Comments