How do I perform the same task (e.g. install packages) on multiple machines?

This page uses adding packages as a specific example of performing a task on multiple machines. The use of rsh and loops for other tasks should be straight forward.

If you need to install a new package on all of the machines in the lab (or even some subset), the standard method of logging into each machine and using /stand/sysinstall to select the package can be tedious (40 logins!) Instead, you can use rsh, pkg_add, and the shared file-system to greatly reduce the tedium. Tip:Always use full pathnames for all programs with rsh.

Preparation

  1. All of the dirt machines should allow .rhost access for root from the master machine (goldberg137). Update the .rhost file in /root as necessary.
  2. You must transfer the tar-ball for the package to a directory that can be accessed on all machines. /usr/src/packages is what I recommend. Use ftp to get the package (or simply copy it if we have a mirror for this version of FreeBSD). For example the package file for emacs19.34 is packages/All/emacs-19.34b.tgz. Copy that file to /usr/src/packages.

Installation

When you're ready to install the package on the remote machine, login to the master machine (goldbergP137), 'su' to root and use rsh. For example (untested):


rsh howard138 "cd /usr/src/packages; /usr/sbin/pkg_add emacs19.34b.tgz"

should install emacs on howard138. To install the package on multiple machines you could do something like (untested):

foreach machine ( howard138 lovey138 speedy138 petunia138 ) 
	rsh $machine "cd /usr/src/packages; /usr/sbin/pkg_add emacs19.34b.tgz"
end

If the command for installation is too complex, you can simply create a script (e.g. /usr/src/bin/add_pkgs) and use


rsh $machine /usr/src/bin/add_pkgs

The value of having a script that simply loops through a list of machines executing a command or script through rsh should be apparent.


Other DiRT documents
Author: Mark Parris
Last updated: December 14, 1998