Live data from Hacker News

Expect – Linux tool for automating interactive programs

linux.die.net

31–40 of 92 posts

Re: Expect – Linux tool for automating interactive programs

#31
post #10

Expect predates Linux by years. It is an old school portable program.

It looks like Expect was first released in 1990 and Linux in 1991 although Linux wasn't really that usable until around 1993.

I don't think it's unfair to say that they iterated on Linux until it could run expect :-)

Re: Expect – Linux tool for automating interactive programs

#33
post #6

I used expect a ton years ago, for AIX system janitoring. A lot of things required telnet’ing into proto-ncurses mainframe applications and going through menus, typing and selecting stuff etc. The actual productive workflow is to do your task with autoexpect, and then refine the generated output: https://linux.die.net/man/1/autoexpect

I really rail to understand why modern unix OS scripting has not made expect obsolete. But then again bash is state of the art, right?

Meta shells and meta meta shells should be an assumed feature by now, not a hit or miss of terminal program feature sets, and not tied to UI programs.

Re: Expect – Linux tool for automating interactive programs

#36
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 tool you need when you're in environments you don't deserve.

Re: Expect – Linux tool for automating interactive programs

#38
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 reconfiguration of a handful of these things, I instead wrote a fairly complex expect script to make the appropriate changes and also validate all the settings on the rest of the raid controllers in a fraction of the time it would have taken to do it manually. It saved me so much hassle and got me some pretty good kudos and respect from my direct leads. It's one of those tools that I kind of wish I would need to use again!

Re: Expect – Linux tool for automating interactive programs

#39

Many years ago I used the Perl version of Expect ( https://metacpan.org/pod/Expect ) to automate several workflows that wanted manual inputs. I thought that it was far better than the TCL Expect because I could also use other CPAN modules and have Perl's regular expressions to parse the system's output. Expect is a great tool to have in your toolkit.

> Perl's regular expressions to parse […]

To be fair, Tcl has Henry Spencer’s regexp[0][1], and is awesome; Postgres also base their regex on Henry’s work for Tcl[2]. Perl is certainly famous for its regex and popularizing thinking of problems in terms of regexes (for better or for worse[3]), but it’s not the only game in town.

[0] https://en.wikipedia.org/wiki/Henry_Spencer

[1] https://wiki.tcl-lang.org/page/Regular+Expressions

[2] https://github.com/postgres/postgres/blob/master/src/backend...

[3] https://stackoverflow.com/questions/1732348/regex-match-open...

Re: Expect – Linux tool for automating interactive programs

#40

expect is one of those true love/hate things. Probably because the situations in which you need to use it are likely cursed. My time spent dealing with expect scripts is always miserable, and yet I don't know what I'd do without it

I've mostly used it for testing and scripting CLIs. Are there any better ways to do that?
Post reply on HN