Expect script to wait for Heroku ssh prompt

215 views Asked by At

I want to use an expect script to run an SSH command on Heroku dynos (for example: Get IP of Heroku dynos)

The exact output when logging into the dyno is:

 ▸    heroku-cli: update available from 6.12.9 to 6.14.21-d83c94b
Establishing credentials... done
Connecting to <dyno> on ⬢ <app>...
~ $

I'm sure the first line would be gone after updating. It takes several seconds for this authentication/login to actually occur.

A simple expect script could go like this:

#!/usr/bin/expect
spawn "./ssh_into_heroku"
expect "xxxx"
send "my_command"

I've tried expect "~ $" { send "my_cmd" } and expect "~ $ " { send "my_cmd" } but neither are working and I have no idea how to debug this.

What would go in the "expect" portion to make this work?

1

There are 1 answers

0
glenn jackman On BEST ANSWER

You're waiting for the prompt that ends with a space, a dollar sign and (I'm guessing) another space. You would use this:

set prompt_regex { \$ $}
expect -re $prompt_regex