Computer access with PAC

Remote Service


The Perl Auto Connector can help ease the administration burden of managing a large number of remote servers.

By Falko Benthin

wad, 123RF

Administrators who manage many remote servers can benefit from tools to help them automate repetitive tasks and updates. One convenient approach for remote access to other computers is the PAC SSH, Telnet, and FTP client. PAC (Perl Auto Connector) [1] is licensed under the GPLv3 and was implemented by David Torrejon Vaquerizas. The remote access client remembers previously used connections, cooperates with proxies, and handles Expect, a tool programmed in TCL that helps automate console-based tasks [2]. Thanks to Expect, administrators can set up tunnels or multiple SSH connections and automate password entries.

Getting Started

Ubuntu users have an easy option: They just add the PAC Repository [3] to /etc/apt/sources.list, then give the commands

# apt-get update
# apt-get install pac

to install the tool and all of its dependencies. Alternatively, the instructions under the Welcome tab [3] help you update your third-party repository (Settings | Repositories | Other Software in the Synaptic package manager) with the correct PPA and GPG key. Then, you can install PAC Manager with the Install this now button at the website. If you use another distribution, you need to download the source code and resolve the dependencies manually, which can be a very time-consuming task.

After completing the installation, you will find a PAC entry in the Applications | Internet menu; alternatively, you can launch the application by typing pac at the command line. If you also pass in the -start_tray parameter, PAC will disappear into the system tray of the panel.

PAC has a tidy interface that supports intuitive use. This is a good thing, because - apart from a fairly rudimentary man page - the application has no help. Before PAC will open a connection to a computer, you need to create a group for what PAC calls the environment. An environment can be your home network, your own server farm, or the computers in the enterprise.

After creating a group, you can assign computers to it. Besides the IP address, username, and password, PAC also wants to know if it should use SSH, FTP, or Telnet to open the connection to the other end and what name you would like to assign to the matching tab (Figure 1). After filling out and storing the details, nothing will stop you from opening a connection. Clicking Connect opens a terminal window that displays the prompt for the remote PC.

Figure 1: Setting up a new connection in PAC is easy.

Thus far, PAC hasn't done anything very special. But one option that makes life easier for admins is customizing the connection for each server. For example, you can define commands that execute on the machine by running PACKAGE before opening and after breaking the connection, and you can store a bunch of commands for the remote machine and just click to execute them (Figure 3). Also, you can search the terminal output for specific terms or to group similar servers in clusters to run predefined commands on all the computers belonging to the cluster (Figure 2).

Figure 2: Grouped as clusters, many servers are just as easy to manage as one.

Figure 3: You can define frequently used commands for each server and click to execute them.

Expect

Expect allows PAC to respond to certain output on the remote machine and automatically run a series of predefined commands. For example, an Ubuntu server on the sample network informs users of update options when they log in; I want to configure PAC to update the remote system whenever updates are available.

The message the server outputs is X packages can be updated. If X is greater than 0, I want Expect to tell the remote computer to update its package lists (apt-get update) and then install the newer packages (apt-get upgrade). Expect uses regular expressions, which it compares with the terminal output. The regular expression that describes the output for package updates is:

^[123456789][0123456789]*\ packages\ can\ be\ updated\.

That is, when the server outputs a line, starting with a number (and no leading zero), followed by the "packages can be updated." string, Expect reports a match, and the command defined in the configuration executes.

Ubuntu does not have a root user, so it needs apt-get in combination with sudo. Also, tell Expect to look for a string with a password prompt then provide the password. Once the system updates its package lists, the command-line prompt reappears, which tells Expect to send the upgrade command (Figure 4).

Figure 4: Regular expressions and commands prompt the remote computer to run a variety of tasks automatically.

You must be very precise about the order of regular expressions; otherwise, the Expect commands never execute. In our lab, an initial <command prompt> was missing - this is a regex that PAC includes and which you can insert into the input box by right-clicking. The missing prompt meant that Expect initially refused to compare the regular expressions with the server output.

Conclusions

PAC is a neat tool for administrators who manage a large number of remote servers and are tired of manually entering frequently recurring sequences of commands. Once you have the server working as intended and you are sure it sends the output you need, the built-in Expect tool lets you automate many tasks. The ability to group many similar machines in clusters and run identical commands on them is a time savings for the admin.

PAC has a clear-cut interface that supports intuitive use, for the most part. On the downside, the documentation is fairly rudimentary as of this writing, causing puzzled looks on administrators's faces when something didn't work as intended. Thankfully, developer Vaquerizas is a really helpful guy who answers your questions quickly. When you ask for support, you can also use the screenshot tool to provide helpful information (Figure 5).

Figure 5: If needed, you can document the PAC terminal window with a screenshot.
INFO
[1] PAC: http://sites.google.com/site/davidtv/
[2] Expect: http://sourceforge.net/projects/expect/
[3] PAC repository: http://www.getdeb.net/software/PAC%20Manager