HostedDB - Dedicated UNIX Servers

-->
Internet Security Professional Reference:Understanding TCP/IP
Previous Table of Contents Next


rsh, remsh, and rcmd

These three commands all perform a similar function, which is to execute a command on a remote system. Interactive commands are not good candidates for this type of execution.

The rsh implementation of remote execution is not to be confused with the restricted shell (rsh) that exists on System V Unix systems. Likewise, some System V Unixes use remsh instead of rsh also. Typically, the systems that use rsh for remote execution are BSD-based Unix systems. rsh works by connecting to the specified hostname and executing the specified command. rsh copies its standard input to the remote command, the standard output of the remote command to its standard output, and the standard error of the remote command to its standard error. Interrupt, quit, and terminate signals are propagated to the remote command; rsh normally terminates when the remote command does.

The command syntax of rsh is as follows:

rsh [ -l username ] [ -n ] hostname [ command ]
rsh hostname [ -l username ] [ -n ] [ command ]

The execution of a command involves entering the name of the host where the command is to be executed and the name of the command. Running rsh with no command argument has the effect of logging you into the remote system by using rlogin. The following example illustrates using rsh to execute commands:

% rsh oreo date
Mon Oct 10 17:23:43 EDT 1994
% rsh oreo hostname
oreo.widgets.ca
%

There are only two options to rsh, as shown in table 1.12.

Table 1.12
rsh Options

Option Description

-l username Use username as the remote username instead of your local username. In the absence of this option, the remote username is the same as your local username.
-n Redirect the input of rsh to /dev/null. You sometimes need this option to avoid unfortunate interactions between rsh and the shell that invokes it. If, for example, you are running rsh and start an rsh in the background without redirecting its input away from the terminal, it will block even if no reads are posted by the remote command. The -n option prevents this.

Virtually any command on the remote system can be executed. Commands that rely upon terminal characteristics or a level of user interaction, however, are not good candidates for the use of rsh.

The rcmd command is virtually identical to the rsh except that it typically is found on System V systems. Actually, the rcmd has the same options and operates the same fashion as the rsh command under BSD Unix. The following illustrates rcmd accessing a remote system by not specifying a command when starting rcmd:

$ rcmd chelsea
Last login: Mon Oct 10 17:18:10 from oreo.widgets.ca
SunOS Release 4.1 (GENERIC) #1: Wed Mar 7 10:59:35 PST 1990
%

The use of rsh/rcmd can be of value when you want to run a command on the remote system without having to log into that system. Some system administrators use it to see what processes are running on a remote system, as shown here:

$ rcmd gateway ps -ef | more
     UID   PID  PPID  C   STIME TTY  TIME  COMMAND
    root     0     0  0  Sep 22   ?  0:00  sched
    root     1     0  0  Sep 22   ?  23:36 /etc/init -a
    root     2     0  0  Sep 22   ?  0:00  vhand
    root   221     1  0  Sep 22   ?  0:00  strerr
    root   150     1  0  Sep 22   ?  7:51  /etc/cron
    root   212     1  0  Sep 22   ?  0:35  cpd
    root   156     1  0  Sep 22   ?  3:21  /usr/lib/lpsched
    root   214     1  0  Sep 22   ?  0:00  slink
    root   317   315  0  Sep 22   ?  0:00  nfsd 4
    root   256     1  0  Sep 22   ?  0:00  /usr/lib/lpd start
  topgun   5740    1  0 10:30:51  2A 0:19  /etc/pppd 198.73.137.101:
                                           log /usr/lib/
                                           ppp/ppp-users/topgun/log
                                           debug 2 nolqm
    root   306     1  0  Sep 22   ?  0:00  pcnfsd
    root 17008   234  0  Sep 29   ?  0:07  telnetd
    root 17009 17008  0  Sep 29   p0 0:02  -sh
    root   286     1  0  Sep 22   ?  0:05  snmpd
$


Previous Table of Contents Next