Live data from Hacker News

Don Libes' Expect: A Surprisingly Underappreciated Unix Automation Tool

blog.robertelder.org

11–20 of 106 posts

Re: Don Libes' Expect: A Surprisingly Underappreciated Unix Automation Tool

#13
post #7

Expect is cool, I have used it in the past as well as the expect perl module, but in my opinion is always a suboptimal way to automate things. It's always better and more robust to have a proper interface to script things instead of relying on matching brittle text/regex responses and timers and such. Of course sometimes it's not possible, so expect comes in handy.

I 100% agree. If I can use paramiko/fabric or something similar, I prefer it way more than expect. If you have a slave device over RS232, expect is probably your only option. But if that remote item is running sshd, you are way better off without expect.

what's wrong with expect spawning ssh??

Re: Don Libes' Expect: A Surprisingly Underappreciated Unix Automation Tool

#15
post #7

Earlier quoted context omitted.

I 100% agree. If I can use paramiko/fabric or something similar, I prefer it way more than expect. If you have a slave device over RS232, expect is probably your only option. But if that remote item is running sshd, you are way better off without expect.

what's wrong with expect spawning ssh??

I think expect is often used to have it enter username and password "interactively". But it's easier and more robust to just use the public-key auth facility that is built-in to ssh.

Re: Don Libes' Expect: A Surprisingly Underappreciated Unix Automation Tool

#16

Earlier quoted context omitted.

what's wrong with expect spawning ssh??

I think expect is often used to have it enter username and password "interactively". But it's easier and more robust to just use the public-key auth facility that is built-in to ssh.

Not always possible. The problem is that ssh lives in the mythical land of perfect security, where people never need to do unsafe things in order to get their jobs done.

Hence keys silently not working without "correct" permissions, passwords not passable on the CLI, inconsistent type-yes-to-override behavior, and other user-hostile design choices.

I love openssh, but it's a real pain in the ass sometimes.

Re: Don Libes' Expect: A Surprisingly Underappreciated Unix Automation Tool

#18
I'm going to try this out on my own because what I read in the comments makes me think I will find use for it, but if I had to be honest, I did so because of the HN comments. The OP was clearly written and nicely formatted, but as someone with moderate CLI/Bash experience (I do almost all of my data processing via Bash programs and pipes), I didn't really understand what `expect` does. Maybe I needed a simpler example, because I don't uss most of the other parts that are in the example, such as `interact` and `send`. As a Pythonist/Rubyist, I have the added baggage of associating `expect` with unit/line testing.

Maybe expect is not for me, but given the title, I would've loved to see maybe a couple paragraphs of why `expect` is underappreciated...that is, what do typical Unix programmers use instead, because they're ignorant of expect. Much easier for me to understand the perspective of ignorance :)

Re: Don Libes' Expect: A Surprisingly Underappreciated Unix Automation Tool

#19
Expect is a last ditch tool that becomes less and less necessary as automation libraries and remote APIs become more and more common. The examples given are cute but hardly representative of what expect is really for.

The only times I've needed to use expect was to drive weird non-scriptable telnet-based remote systems and to automate unpackaging of intentionally-broken vendor-supplied self-expanding software archives that require some level of interaction.

The point being if you want to create shortcuts to jump to specific locations in a man page or drive outdated appliances or open user-hostile zips, expect is the tool for you!

Re: Don Libes' Expect: A Surprisingly Underappreciated Unix Automation Tool

#20
OMG I have been burned by this so many times. Expect itself is a cool piece of technology and works as well as anyone could hope. However, every time I've tried to use it for anything the solution ends up being super flaky. I think trying to automate text interfaces like this is just fundamentally unreliable.
Post reply on HN