3 ms·
Miniexpect – A very simple expect-like library
- rwmj 4y agoExample 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-sshpass.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 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.pod#HOW-VIRT-P2V-WORKS https://github.com/libguestfs/virt-p2v/blob/master/virt-p2v.... https://github.com/libguestfs/virt-p2v/blob/master/ssh.c https://github.com/libguestfs/virt-p2v/blob/master/ssh.c
- kubb 4y agoWhat'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.
- mkovach 4y agoMy 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.
- elcaro 4y agoOne 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.
- rwmj 4y agoBecause 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.
- sim7c00 4y agolove 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 4y ago
- inops 4y agoIt's LGPL
- rwmj 4y agoIt's LGPLv2+ which doesn't restrict your use in any way — you can combine it with proprietary code, ship it in closed source products etc — but does mean that you must contribute changes (to this library code only) back rather than being able to steal them from the commons for your proprietary benefit.
- neoromantique 4y agoGood.
- Brian_K_White 4y agoIt's a cool unnamed product you work on, but being proprietary means that it's useless for any project I've ever worked on. Did you actually think that anyone could possibly sympathize with a complaint about the intolerability of reciprocity? Whatever product you're working on, if it can't include any gpl code, then it means they give you money instead. Do you hear yourself? "Boo hoo I can't take without giving" ? Or are you claiming that you have only ever worked on MIT projects?
- aaaaaaaaaaab 4y agoYou’re free to contact the author to pay for a commercial license for your projects.
- commonlisper 4y agoNo license is going to be suitable for everyone. You might think BSD, MIT, WTFPL are the most liberal licenses but they are not suitable for me. If I am invested in an open source software enough to contribute code to it then I want that when a greedy company takes that software and improves it and redistributes it they are also forced to release the source code benefitting everyone. BSD, MIT, WTFPL can't do that but GPL can. No license is a silver bullet.
- phoboslab 4y agoThis repo says how it relates to other implementations but curiously fails to mention what "expect" actually is. 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 https://core.tcl-lang.org/expect/index
- masukomi 4y agothanks. i was assuming it was some sort of unit testing thing. "expect" foo to equal bar kinda stuff.
- rwmj 4y agoThanks for the feedback - I've updated the README file.
- pid-1 4y agoAs 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.
- icedchai 4y agoAbout 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.
- RHSeeger 4y agoInterestingly, 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.
- 4y ago
- aidenn0 4y agoI 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.
- imurray 4y agoI 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: 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-a-command-into-thinking-its-output-is-going-to-a-terminal https://unix.stackexchange.com/questions/249723/how-to-trick...