0

I am trying to write an expect script that logs in to my raspberry pi, then goes to the correct folder, then executes a c++ program, and then proceeds to exit the raspberry pi. After that has been done I want the script to run a shell script in my command prompt.

The problem is that I can't get the timing right.

Currently, it looks like this:

#!/usr/bin/expect

# Logs in to to raspberry pi
spawn ssh pi@XXXXXXXXXX
expect "*: "
send "raspberry\r"

# Go in the folder "folder" and run "main_cpp"
expect "$ "
send "cd Documents/folder\r"
send "./main_cpp\r"

# Works fine until this line ###################

# Wait for the executable to finish and then exit raspberry
expect "$ "
send "exit\r"

# Wait for the script to get back to my computer
# and then run the shell script "script.sh".
expect "$ "
send "./script.sh"
expect eof

I get the script to run the main_cpp but the rest doesn't get timed correctly.

I am guessing the expect "$ " and expect "$ " are wrong. I have tried replacing them with both expect -re $prompt and expect "prompt>\r" but neither works as intended.

I am running macOS on my computer and Debian on the raspberry pi.

I would really appreciate some help!

Markus
  • 3
  • 2

0 Answers0