-1

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?

s g
  • 5,289
  • 10
  • 49
  • 82
  • Why is this downvoted? It's very explicit and it follows everything here: https://stackoverflow.com/help/on-topic – s g Sep 13 '17 at 16:34

1 Answers1

1

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
glenn jackman
  • 238,783
  • 38
  • 220
  • 352