As a developer I find myself having to connect to multiple machines several times during the day. I wanted to automate the process and discovered Expect - a tool for automation of interactive applications.

I started using Expect to automate my ssh sessions. And while Tmux is very good at managing multiple sessions I’ve found that for me Emacs and multi-term.el is the best multi session window manager out there.

First I create Expect script to automate the login process:

#!/usr/bin/expect -f
set timeout 20
set IPaddress [lindex $argv 0]
set Username [lindex $argv 1]
set Password [lindex $argv 2]
spawn ssh -o "StrictHostKeyChecking no" $Username@$IPaddress
expect "*assword: "
send "$Password\r"

Then I create my login functions in emacs:

(require 'multi-term)
(defun my-login (host user pwd window-name)
(rename-buffer window-name)
(term-send-raw-string (concat "./" " " host " " user " " pwd))
(setq user1 "userXYZ")
(setq pwd1 "pass1")

After that I create functions to login to different machines:

(defun my-login-server1()
(my-login "" user1 pwd1 "server1-window-title"))

This setup works very well. It helps me in automating the login process and shows a descriptive window title for each session in Emacs.