linux,

spawn, expect and send commands in Linux

Apr 10, 2022 · 1 min read · Post a comment

spawn, expect and send commands are usually part of SSH bash scripts. So, I’m going to briefly explain them, starting with expect since the rest of them are part of it.

Prerequisites

  • Linux bash environment

Example

spawn ssh -o \"StrictHostKeyChecking=no\" \"${USER}@myhost.example.com\"
expect \"${USER}'s password:\"
send \"${PASSWORD}\n\"

Solution

expect is a scripting utility that communicate with interactive scripts.

spawn starts a new process. For instance initiating SSH session as in the example above.

send writes to the spawned process standard input (std). It has a file descriptor value of 0.

Conclusion

Official expect documentation. On a side note, follow our official channel on Telegram.