Live data from Hacker News

Don Libes' Expect: A Surprisingly Underappreciated Unix Automation Tool

blog.robertelder.org

71–80 of 106 posts

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

#71

This tool keeps the command line interpreter (CLI) alive. Sysadmins everywhere can glue hundred different systems from a hundred different vendors together if they have CLI and the sysadmin has access to a machine that runs expect(1). There are many stories of complex infrastructure being taken down by new firmware on routers or switches that change the order of parameters in a command :-)

Rather, this tool keeps alive systems that do not have easily scriptable command interfaces, and must be driven at the character-level through their interactive visual interfaces. If the system has a CLI, you write a script in that CLI; you don't write an expect script. Sometimes systems have CLI, but only behind a remote access wall (telnet, serial, ...); then you might use expect---because there is no way to upload…

   > Sometimes systems have CLI, but only behind a 
   > remote access wall (telnet, serial, ...); then 
   > you might use expect-
All managed switches, all routers, and all PDUs pretty much.

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

#72
A friend taught me about expect by giving me this expect script for logging into our vpn. It automates login using Cisco Anyconnect on a Mac.

  pw=c3-f3-341a
  spawn /opt/cisco/anyconnect/bin/vpn connect vpn.example.com
  expect "Username:*" { send "myname\r" }
  expect "Password:*" { send "$pw\r" }
  interact

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

#73
post #28

I used expect heavily at several clients in the past and have never seen someone else use it. I never used it as a precise tool, rather as a Sledgehammer. I think I remember I used Expect to script remote machines (expect was literally the "programmer") when everything else failed and was "prevented" due to policy. I guess my script was also non-compliant, but noone complained.

I've done the same thing, and on the windows side of things AutoIT ( https://www.autoitscript.com/ ) is similarly flexible when all else fails. It's not pretty, but arguably is a good example of the hacker ethic.

For Windows, I like AutoHotKey - IIRC, it started out as an open-source alternative to AutoIt, but has since grown a significant amount of functionality of its own:

https://autohotkey.com/

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

#74

Don Libes' daughter went to my high school, and I was working as the "webmaster" for the high school newspaper's website at the time. He would ruthlessly criticize via email the product our self-taught and earnest 2010-era PHP web development. I am not a fan of Don Libes. For those interested, the website was/is: http://theblackandwhite.net/

Looking at the link I'm inclined to agree with Don.

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

#75
post #54
post #47

Shameless self promotion: if you want to automate subprocesses with python in an intuitive way, give sh a try: https://github.com/amoffat/sh

Man, I was so happy when I discovered your library. It's how I always felt subprocess should be. With split('\n') and basic string parsing there's little that can't be automated with sh. Keep up the good work!

That makes me happy to hear, thanks!

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

#76
Noah Spurrier did a great job with pexpect, which i helped port to python 3 and add unicode support.

I've been in love with pty's in general since the mid 1990's, and naturally found myself maintaining a highly visible python project about pty's.

love this stuff.

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

#77

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 archive…

Do you have any links to examples of what it is really for? I've had a hard time finding code examples because the reasons listed at the bottom of the article.

[deleted]

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

#78

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.

Is it intended to automate things? It looks like it's meant to save typing with interactive things.

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

#79

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.

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. When I was a graduate Comp Sci TA in the 1990's, it was the perfect way to automate grading the Unix shell that the Systems Software class was supposed to write. Effectively, I was also writing a regression/functional testing system for the class. I explained that the Expect/T…

> I explained that the Expect/Tcl script was going to be used to grade their project, and I provided the code.

If it's deterministic, is there a risk of someone just writing a second Expect script (instead of a solution to the programming exercise) that interacts with yours and gives the replies that you want?

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

#80
post #50

Earlier quoted context omitted.

`info` also contains a lot of historical notes, i.e. $ info Groff | awk '$2 == "History"{f = 4};f && f--' RS= ORS='\n\n' 1.2 History =========== 'troff' can trace its origins back to a formatting program called 'RUNOFF', written by Jerry Saltzer, which ran on the CTSS (_Compatible Time Sharing System_, a project of MIT, the Massachusetts Institute of Technology) in the mid-sixties.(1) (*note History-Footnote-1::) The…

I'm well familiar with Awk RS="" paragraph mode and all, but I'm scratching my head why f = 4 to fetch three paragraphs. [Edit]: Indeed, I ran your command verbatim and obtained one more paragraph: When they needed are more flexible language [...] . You sneaky devil!

> You sneaky devil!

He he. Never copy/paste shell code found on the internet :-)

Post reply on HN