Sams Teach Yourself Shell Programming in 24 Hours
(Publisher: Macmillan Computer Publishing)
Author(s): Sriranga Veeraraghavan
ISBN: 0672314819
Publication Date: 01/01/99

Previous Table of Contents Next


remsh/rsh/rcmd/remote (Remote Shell)

If you have several UNIX systems connected over a network, it is possible to invoke a remote shell to run a command on the remote system and return the output of that command to your screen:

remsh acron who

This shows us who is logged into the remote system called acron. The basic syntax is:

remsh remote-sys unix-command

remote-sys is the name of the remote system where the given unix-command runs. You can pipe text to remsh, which is passed to the unix-command being run on the remote system. Any standard output from unix-command on the remote system is passed to standard output on your system where it can be redirected if desired.

Different types of UNIX systems have different names for this command including: remsh, rsh, rcmd, or remote.

Check the man pages on your system to see which command is correct. Be careful to avoid confusion with the restricted shell command rsh, which is sometimes invoked as /usr/lib/rsh if rsh invokes the remote shell.

Using the remote shell requires setting up /etc/hosts.equiv, which indicates a trust relationship between the two systems. The simplest most trusting setup is to put each system name in the other system’s host.equiv file. Usually the same user account is added to both systems. Then a remote command run by that user on one system runs with the same access permissions for that user on the other system. To use this facility for root, /.rhosts must be set up to contain the other system name.

Here is a more complex example that enables us to copy a whole directory tree to the remote system:

cd /sourcedir
find . -print | cpio -ocva |
        remsh remote_sys \( cd /destdir \; cpio -icdum \)

The find command passes a list of files to cpio, which copies them to standard output. This is passed by the remote shell command to the remote system where the files are restored to the desired destination directory. Notice that many of the special characters must be escaped—that is, preceded by a backslash—so they are interpreted on the remote system and not on the local system.

Summary

In this chapter you have looked at several miscellaneous tools:

  eval
  :
  type
  sleep
  find
  xargs
  expr
  bc
  remsh/rsh/rcmd/remote

A large part of this chapter was spent on the basics of the find command. Peruse the man page on find, and you can see other useful find options for your scripts that I did not cover.

Questions

1.  You are about to run a custom command called process2, but you would first like to determine where that command resides. Give a UNIX command to do this.
2.  How can you determine all directories under /data that contain a file called process2, allowing any possible prefix or suffix to also be displayed (for example, you want to find names such as process2-doc).
3.  How can you increase the numeric value in variable PRICE to be 3.5 times its current amount? Allow two digits to the right of the decimal point.

Terms

no-op
A command that does nothing and thus can be used as a dummy command or placeholder where syntax requires a command.
built-in
A command whose code is part of the shell as opposed to a utility which exists in a separate disk file which must be read into memory before it is executed.
reserved word
A nonquoted word that is used in grouping commands or selectively executing them, such as: if, then, else, elif, fi, case, esac, for, while, until, do, or done.
modulus function
See remainder function.
remainder function
The remainder of a division operation, which is the amount that is left over when the amounts are not evenly divisible.
inode
A table entry within a file system that contains file information such as the owner, group, permissions, last modification date or time, last access date or time, and the block list of the actual file data. There is one inode for each file. The inodes are numbered sequentially. The inode does not contain the filename. A directory is a table that maps filenames to inode numbers.


Previous Table of Contents Next