Original post is here: eklausmeier.goip.de
Occasionally I teach customers and colleagues how to use some aspects of Linux, or how to use and administrate newly developed software on Linux. I regularly use either VNC or kibitz for this. While VNC is somewhat known to many people, kibitz seems to be like a hidden germ, unbeknownst to many.
With VNC two, or even more people, can see what each person is typing, on the screen, and at the same they can also type, or move the mouse, which everybody can see and witness.
[more_WP_Tag]kibitz is similar to that, except, there is no mouse, no graphical component. It works with simple text screens. So everything you type into your shell, the guy at the other end will also see, and vice versa, what he types, you will see as well. You can edit files together, change users together, and so on. It is particular handy if the machine in question does not have any graphical stuff, like Gnome, KDE, Xfce, IceWM, etc. kibitz works with two or more users. Unfortunately it is not always installed by default on Ubuntu or Red Hat.
kibitz is a script written in the Expect programming language, which is based on Tcl/Tk. The script size is not more than 500 lines.
expect is a command which is very useful if you want to automate something which originally was never really ment to be automated. One prominent example is ftp. The ftp command usually does not contain any macro language, or any other form for automation, disregarding lftp for the moment. With expect it is very easy to automate file transfers, checking for succesful transfer, and so.
Below you'll find an example for transfering files to a hosting company via ftp. The challenge is that the hosting company closes its connection very early. So you have to constantly log-on to transfer your files.
1#!/usr/bin/expect
2
3puts $argc
4puts $argv
5
6set timeout -1
7spawn ftp ftp-host-name-goes-here
8expect "220 Welcome"
9expect "Name*:"
10send "my-user-name\r"
11expect "331 Password"
12expect "Password:"
13send "my-secret-password\r"
14expect "230 User"
15expect "ftp>"
16
17
18if {$argc <= 1} {
19 #puts "At least two arguments expected."
20 interact
21 exit 0
22}
23set cmd [lindex $argv 0]
24if {$cmd != "put" && $cmd != "get" && $cmd != "del"} {
25 puts "Command must be either put or get or del"
26 exit 2
27}
28
29for {set i 1} {$i < $argc} {incr i} {
30 set argvi [lindex $argv $i]
31 send "$cmd $argvi\r"
32 if {$cmd == "del"} {
33 expect "250 DELE"
34 } else {
35 expect "226 Transfer"
36 }
37 expect "ftp>"
38}
39send "quit\r"
40expect "221 Goodbye"
So you can edit files on your machine, and then just call above script and transfer your file to the hosting company, without entering user name and passwort all the time, and directly telling ftp what to do, here put, get, or del.
The Expect programming language is explained in the book by its creator Don Libes: "Exploring Expect: A Tcl-based Toolkit for Automating Interactive Programs", O'Reilly & Associates.
(Amazon told me that I bought this book at 20-Nov-2003, i.e., ten years ago.)
BTW, expect and kibitz are not tied to Linux. You can find them on any Unix system, even on Windows.