Miniexpect – A very simple expect-like library(github.com)
github.com
Miniexpect – A very simple expect-like library
https://github.com/rwmjones/miniexpect
22 comments
As an intern, I used expect in my first job to create a monitoring system for ~ 200 L3 Routers in a private network. Eventually I learned about SNMP and also that I probably should Google "How to X" before rolling out my own solution for anything.
Interestingly, I did something very similar in my first job, though it included backing up configurations and the like. It's worth noting that a lot of routers (at that time) didn't really support much in the way of SNMP. As such, one had to navigate menus to get to the necessary options; and nothing is as potent as Expect at that kind of thing.
About 20 years ago, I built a system for L3 router configuration using expect. It basically allowed support people to move a port's VLAN and change its status from a web app. It was for a local telco and they used it for a couple of hospitality / hotel customers, IIRC.
Thanks for the feedback - I've updated the README file.
thanks. i was assuming it was some sort of unit testing thing. "expect" foo to equal bar kinda stuff.
It used to be hosted by https://nist.gov/ at expect.nist.gov
Here is it in 1997, it hasn't changed much.
https://web.archive.org/web/19971210131642/http://expect.nis...
Here is it in 1997, it hasn't changed much.
https://web.archive.org/web/19971210131642/http://expect.nis...
I won't lie, I've used the original expect just because I needed to force a program to run in a pty. It turns out that script(1) will also do this though.
I used to use `unbuffer` which comes with expect, and might be what you used too. I now use the following hack, which works faster:
Create isatty.so like this:
Create isatty.so like this:
echo "int isatty(int fd) { return 1; }" | gcc -O2 -fpic -shared -ldl -o isatty.so -xc -
Then to make `some_program` think it's in a tty: LD_PRELOAD=./isatty.so some_programe
Source and more: https://unix.stackexchange.com/questions/249723/how-to-trick...Example showing how to use this library to ssh to a remote machine with a password and send a command:
https://github.com/rwmjones/miniexpect/blob/master/example-s...
I think the library is quite elegant because it essentially does very little itself. It's implemented almost entirely using the "partial match" feature of PCRE: https://pcre.org/current/doc/html/pcre2partial.html This means it can use the super-powerful regexps in PCRE, while itself being only a few hundred lines of code.
This library has been used for years (since 2014) to do physical to virtual machine conversions, specifically for connecting from the physical machine to the remote hypervisor and automating virt-v2v: https://github.com/libguestfs/virt-p2v/blob/master/virt-p2v.... https://github.com/libguestfs/virt-p2v/blob/master/ssh.c
https://github.com/rwmjones/miniexpect/blob/master/example-s...
I think the library is quite elegant because it essentially does very little itself. It's implemented almost entirely using the "partial match" feature of PCRE: https://pcre.org/current/doc/html/pcre2partial.html This means it can use the super-powerful regexps in PCRE, while itself being only a few hundred lines of code.
This library has been used for years (since 2014) to do physical to virtual machine conversions, specifically for connecting from the physical machine to the remote hypervisor and automating virt-v2v: https://github.com/libguestfs/virt-p2v/blob/master/virt-p2v.... https://github.com/libguestfs/virt-p2v/blob/master/ssh.c
What's the reason behind writing automation tooling in C instead of higher level languages? The usual (portability, performance) don't seem to apply at first glance.
My thoughts exactly. I love using expect, but why would I write a C program when I quick and simple TCL script (expect is build with TCL and is threaded and easy to make thread-safe scripts).
There are also expect clones in Python and Perl (probably others, but I know and have used those both) if TCL is an issue for you.
This looks nice, but I don't see if as very useful.
There are also expect clones in Python and Perl (probably others, but I know and have used those both) if TCL is an issue for you.
This looks nice, but I don't see if as very useful.
One potential use case could be in creating bindings for other languages that do not have an expect like module. Since it reportedly has a "saner interface than libexpect", it might be less hassle creating FFI bindings to mini-expect.
Because the program it's used in is written in C too, as is most software that runs on Unix-like systems. It uses and depends on another C library (PCRE). The P2V system has to fit on a small bootable ISO, so minimising code size and dependencies is an overriding concern. Also it was written in 2014.
love it, only knew expect from python, so quite happy to find a c library :D thanks!! (stubborn person who would write a website in C here!!)
efitz(6)
So for everyone as ignorant as myself, I guess it's referring to this[1]:
> Expect is a tool for automating interactive applications such as telnet, ftp, passwd, fsck, rlogin, tip, etc.
[1] https://core.tcl-lang.org/expect/index