2 ms·
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/examp
by rwmj 4y ago
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-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!!)