I have an expect script that logs into my Beaglebone:
#!/usr/bin/expect -f spawn ssh debian@192.168.7.2 expect "debian@192.168.7.2's password:" send "temppwd\r" interact && mkdir emma && cd emmaThis works and it logs into the debian account. However, it stops after interact the other two commands are not being executed. What do I have to do to do that ?
EDIT
ok so thanks andy256 I figured that interact is wrong here, however, I get
invalid command name "mkdir" while executing
How can I combine an expect script with normal shell script?
Thanks in advance !
51 Answer
The main thrust of expect programming is send and expect pairs: you send some text to the spawned process and expect a response. In this case, you send the mkdir command, and expect to see your prompt to know that the command has completed. Prompts are best matched as regular expressions to match the end of it. Since prompts are so configurable, you might want to edit the prompt expression: this one matches a literal dollar sign and a space at the end of the string.
#!/usr/bin/expect -f
spawn ssh debian@192.168.7.2
expect "debian@192.168.7.2's password:"
send "temppwd\r"
set prompt_re {\$ $}
expect -re $prompt_re
send "mkdir -p emma && cd emma\r"
expect -re $prompt_re
interact 0