empty - run processes and applications under pseudo-terminal (PTY) sessions and replace TCL/Expect with a simple shell-tool

SourceForge.net Logo

Common shell (sh, bash, ksh, csh, tcsh) in conjunction with standard UNIX tools like cat, find, grep, sed and such can bring you all the power of full featured scripting language. In other words, you often do not need to intall and use more powerful languages as Perl, PHP, TCL, Python, etc.
Support This Project But often doesn't mean always, and one of the oldest problems was the use of Command-line interactive programs in UNIX shell-scripts. The target of this project is to solve the problem and give an opportunity to simplify the management of interactive applications in common sh-scripts.

empty is an utility that provides an interface to execute and/or interact with processes under pseudo-terminal sessions (PTYs). This tool is definitely useful in programming of shell scripts designed to communicate with interactive programs like telnet, ssh, ftp, etc. In some cases empty can be the simplest replacement for TCL/expect or other similar programming tools because empty:

  • can be easily invoked directly from shell prompt or script
  • does not use TCL, Perl, PHP, Python or anything else as an underlying language
  • is written entirely in C
  • has small and simple source code
  • can easily be ported to almost all UNIX-like systems

Nowadays empty was successfully compiled and tested on:

download empty now!

  • FreeBSD 5.x - 8.x
  • NetBSD 1.6.2, 2.0
  • OpenBSD 3.3, 3.8, 4.1
  • Linux 2.4.x, 2.6.x kernels (32 and 64bits)
  • SCO UnixWare 7.1.1, OpenUnix 8.0.0
  • SUN Solaris 6-10 (Sparc: cc, gcc), 8 (i386: gcc)
  • HP-UX 11.00, 11.11, 11.23 (pa-risc, itanium)
  • Cygwin DLL-1.5.19-4 (Experimental, see README.CYGWIN)
  • OSF1 4.0, 5.1
  • AIX 4.3, 5.1, 5.2, 5.3

Installation is simple: download, then ungzip and untar the source code:

	tar zxvf empty-x.y.z.tgz

If you have Linux or *BSD just run:

	make all install clean

on any other *NIX try:

	make `uname -s` all install clean
	 or
	make `uname -s`-gcc all install clean

This will compile and place empty with its manual page under /usr/local tree. Good luck and beware of bugs!


empty was written by Mikhail E. Zakharov on the basic idea of pty-4.0 Copyright (c) 1992, Daniel J. Bernstein, but no code was ported from it.

Thanks to:

  • Aleksey Kozlov - avtolik@newmail.ru
  • Alexey Rudometov - rudometov@u-systems.ru
  • Alex Slyotov - aslyotov@gmail.com
  • Dmitry S. Vlasov - vlasov@quantum.ru
  • Elisender - allex_9@ngs.ru
  • Lang Qiu - qiulang@gmail.com
  • sdio - sdio4lor @ gmail.com
  • Sergey Redin sergey@redin.info
  • Sergey V - flexdsl@mail.ru
  • Sergey Yaroshevsky - astraserg@proc.ru
  • Sylvain DEGUT - sylvain.degut@neuf.fr
  • Vincenzo Maggio - vince.maggio@gmail.com

I express deep gratitude to Hewlett Packard AO Russia and personnaly to Denis Karzhavin and Andrew Kuchinsky for C110 (9000/777) workstation

empty
#!/bin/sh
empty -f -i in -o out telnet foo.bar.com
empty -w -i out -o in "ogin:" "luser\n"
empty -w -i out -o in "assword:" "TopSecret\n"
empty -s -o in "who am i\n"
empty -s -o in "exit\n"
TCL/Expect
#!/usr/bin/expect

spawn telnet foo.bar.com 
expect ogin {send luser\r}
expect assword {send TopSecret\r}
send "who am i\r" 
send "exit\r"
expect eof
Perl/expect module
#!/usr/bin/perl

use Expect;

my $exp = Expect->spawn("telnet foo.bar.com");
$exp->expect($timeout,
        [ 'ogin: $' => sub {
                     $exp->send("luser\n");
                     exp_continue; }
        ],

        [ 'assword:$' => sub {
                      $exp->send("TopSecret\n");
                      exp_continue; }
        ],
        '-re', qr'[#>:] $'
);
$exp->send("who am i\n");
$exp->send("exit\n");
$exp->soft_close();
Python/Pexpect
#!/usr/local/bin/python

import pexpect

child = pexpect.spawn('telnet foo.bar.com');

child.expect('ogin: ');
child.sendline('luser');

child.expect('assword:');
child.sendline('TopSecret');

child.sendline('who am i');
child.sendline('exit');

child.expect(pexpect.EOF);

print child.before;

These examples above show the same quick telnet session using empty and various scripting languages.


http://www.iterating.com/products/Empty




One of the versions of empty with several modifications by Sergey Zhumatiy (serg[at]parallel.ru) was recently included into Cleo - the task management system for clusters (http://parcon.parallel.ru/cleo.html). Now empty works for clusters at Lomonosov Moscow State University in Russia


Copyright (C), 2005-2009 Mikhail E. Zakharov