Live data from Hacker News

Expect – Linux tool for automating interactive programs

linux.die.net

61–70 of 92 posts

Re: Expect – Linux tool for automating interactive programs

#62

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

> the situations in which you need to use it are likely cursed.

So true, and yet so common.

Re: Expect – Linux tool for automating interactive programs

#63

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 the case of entering passwords, you can just use ssh authentication instead

Re: Expect – Linux tool for automating interactive programs

#64
post #31

Earlier quoted context omitted.

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 :-)

Yeah, I remember reading some posts around 1993 where someone wanted to port some existing Unix program to Linux. Instead of modifying the program they added the missing functionality to Linux. I think it was about polling and signal handling or something like that.

Re: Expect – Linux tool for automating interactive programs

#65
post #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.

OP here, you must have missed my original comment where I said that claude.ai suggested this to me.

Re: Expect – Linux tool for automating interactive programs

#66

> Cause your computer to dial you back, so that you can login without paying for the call. I don't understand what this means, but it sounds like an interesting piece of 'how we used to do things'?

In the days of landline service, you have to pay for long distance calls; so it mattered which side made the call, as the originator of the call was charged. So you make a quick call to have the computer call you back and stay on for a long time; the number associated with the computer location is billed.

Re: Expect – Linux tool for automating interactive programs

#67

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…

out of curiosity, why do you call the expect script in string form from a bash shebang, rather than make the script itself an expect script directly with an explicit expect shebang?

Re: Expect – Linux tool for automating interactive programs

#68
Expect was the first tool that really hooked me at my first job at Sun. I had to write a tool to automate verification of the boot process during firmware dev, handling variety of odd/unexpected behaviors, paths, and prompts.

Many years later I heard they were still relying on that tool!

Re: Expect – Linux tool for automating interactive programs

#69
post #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…

>> Perl is certainly famous for its regex and popularizing thinking of problems in terms of regexes (for better or for worse), but it’s not the only game in town.

Agreed.

In that old system we did not have any TCL scripts or third-party libraries--just C, Perl, and C shell (no Bash; it was Unix).

C shell scripting is painful (https://www.grymoire.com/Unix/Csh.html), so practically all scripting was Perl or occasionally AWK.

Re: Expect – Linux tool for automating interactive programs

#70

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 the case of entering passwords, you can just use ssh authentication instead

There's certain devices (e.g. firewalls) that don't allow you to save your public key for SSH authentication, so you're stuck with passwords. I've used "expect" for automating backups to a TFTP server.
Post reply on HN