Live data from Hacker News

Expect – Linux tool for automating interactive programs

linux.die.net

41–50 of 92 posts

Re: Expect – Linux tool for automating interactive programs

#41

My go-to example for `expect` is password-based SSH. Since we're all enlightened beings these days who surely never use this anymore, there's no risk to it: #!/bin/bash expect -c " spawn ssh user@10.0.0.1 expect \"password:\" send \"12345\r\" interact " `interact` hands you back control to do whatever you want, but you don't actually need to do that. You can have `expect` run every command, fill out every field. The…

For this particular use case, I'd suggest sshpass instead.

  https://linux.die.net/man/1/sshpass
...

Operations folks today might not understand -- everything just works nowadays, which is slightly boring. And boring is good!

But there's something unique about the feeling of making things work even though they are not designed to work, and really have no right to work. Expect has been a lifesaver for some of the most critical systems at some of the biggest companies in the world.

No aspersions cast by me!

Re: Expect – Linux tool for automating interactive programs

#42
post #22

I use pexpect frequently for automating serial-port communications. It’s very useful for implementing test/flashing automation that needs some kind of a serial-port step (such as asking u-boot to run a few commands).

I do something very similar, how do you deal with random serial port data loss (dropped bytes)? Maybe it is specific to my environment, but I get mangled commands about 1% of time, which really sucks for automated workflows. I mostly countered this by writing commands to a tmp file, verifying md5sum and then executing the file on the device side.

Re: Expect – Linux tool for automating interactive programs

#43
post #3

Good example of an LLM suggesting something useful, even if just RTFM for forgotten tools. O’Reilly put out a book about expect back in the old days (1995). I used expect a few times to automate remote admin, and even to scrape terminal-based applications.

What? It's a manual page.

Re: Expect – Linux tool for automating interactive programs

#44
post #41

My go-to example for `expect` is password-based SSH. Since we're all enlightened beings these days who surely never use this anymore, there's no risk to it: #!/bin/bash expect -c " spawn ssh user@10.0.0.1 expect \"password:\" send \"12345\r\" interact " `interact` hands you back control to do whatever you want, but you don't actually need to do that. You can have `expect` run every command, fill out every field. The…

For this particular use case, I'd suggest sshpass instead. https://linux.die.net/man/1/sshpass ... Operations folks today might not understand -- everything just works nowadays, which is slightly boring. And boring is good! But there's something unique about the feeling of making things work even though they are not designed to work, and really have no right to work. Expect has been a lifesaver for some of the most c…

Definitely, `sshpass` is the more better keyhole tool for this job. I picked it as the most common example I can imagine everyone going "ugh, I have to do this by hand again?" at.

Re: Expect – Linux tool for automating interactive programs

#46

Earlier quoted context omitted.

I don’t think you understand nor used the program expect before Pyexpect is in another class of software. It is a Python testing utility that provides expressive assertions for unit testing. On the other hand, the Unix expect program, and its Python equivalent pexpect, are used for automating interactive applications.

I suppose he/she meant pexpect https://pypi.org/project/pexpect/

Thank you

Re: Expect – Linux tool for automating interactive programs

#47

Expect is such a great tool for a specific class of problem. Decades ago I worked as a test engineer for a big hardware vendor. We had maybe a couple hundred raid controllers that we were testing and to address some issues we found, the supplier needed us to change a bunch of configuration variables that were only accessible via a text menu system over a serial connection to these devices. After painful manual reconf…

this is the sort of context I've also seen expect use. hardware test automation in manufacturing xD

Re: Expect – Linux tool for automating interactive programs

#49

My go-to example for `expect` is password-based SSH. Since we're all enlightened beings these days who surely never use this anymore, there's no risk to it: #!/bin/bash expect -c " spawn ssh user@10.0.0.1 expect \"password:\" send \"12345\r\" interact " `interact` hands you back control to do whatever you want, but you don't actually need to do that. You can have `expect` run every command, fill out every field. The…

You forgot all the other prompts that ssh might produce before the password prompt (e.g. add new host to known hosts yes/no). There are more possible prompts than most people realize.
Post reply on HN