0

I´m getting crazy trying to make this works.

I need to use expect to set a couple passwords. The problem that I have is that I have to run two commands in the same processor.

Here the code

   yum install -y expect
   secret="price_aws_git_secret.txt"
   eval $(ssh-agent)
   pass=$(cat $secret)
   expect << EOF
          spawn ssh-agent ssh-add price_aws_github
          expect "Enter passphrase"
          send "$pass\r"
          spawn git clone git@github/repo.git
          expect "Are you sure you want to continue connecting"
          send "yes\r"
          expect eof                 
   EOF

The first command add into the ssh-agent the ssh key, and the second command the git clone need to be in the same process to get that agent.

Looking documentation and examples I´m not able to see how expect can works with two commands in the same process.

Any suggestion?

Thanks!

3
  • As usual, you should be able to avoid expect altogether by setting up public-key authentication instead. Commented Jul 28, 2016 at 16:03
  • It´s what I did, but even adding a public-private key on github you need to provide a password when you want to add the private key to the ssh-add Commented Jul 28, 2016 at 16:06
  • You're going to great lengths. Why don't you create a key with no passphrase? Commented Jul 28, 2016 at 22:02

1 Answer 1

2

Suggestions about using ssh keys better aside, to answer your question. You don't need to interact with two processes at the same time. You need to handle the first one, then start the second:

expect << EOF
      spawn ssh-agent ssh-add price_aws_github
      expect "Enter passphrase"
      send "$pass\r"
      # assume this works. if not, there's more work to do
      expect eof
      close

      spawn git clone git@github/repo.git
      expect "Are you sure you want to continue connecting"
      send "yes\r"
      expect eof                 
EOF
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.