0

I have an expect script that logs into my Beaglebone:

    #!/usr/bin/expect -f
    spawn ssh [email protected]
    expect "[email protected]'s password:"
    send "temppwd\r"
    interact &&
    mkdir emma &&
    cd emma

This 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 !

5
  • 1
    I guess because the interact command gives control of the current process to the user.
    – andy256
    Nov 29, 2015 at 4:46
  • ah okk, I took it out but then I get a command unknown error for mkdir Nov 29, 2015 at 4:51
  • 1
    Why not adding your public key to the server to have password less login and run your command with ssh [email protected] <command>? Would be lot easier than fiddling with expect
    – Germar
    Nov 29, 2015 at 5:21
  • I tried that with [email protected] ' "temppwd\r" ' but didn't work Nov 29, 2015 at 5:45
  • it stops at the pw question Nov 29, 2015 at 5:45

1 Answer 1

5

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 [email protected]
expect "[email protected]'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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .