The remote shell command rsh allows you to execute a command on a remote machine without actually logging onto that machine. Beware that on some Unix System V machines, rsh is the name for the restricted shell, in which case you get a remote shell by issuing the rshell or rcmd commands. The command rsh uses the same .rhosts file as does rlogin, yet while rlogin will prompt you for a password if it has trouble with the .rhost file, both rsh and rcp require a properly functioning .rhosts file. If the .rhosts files is not properly configured, these commands will issue an error message and quit.
In the example below, big brother bohr wants to find out if his
students are working on phy1 (as they were told to), and so he runs
the command who remotely on the machine phy1:
% rsh phy1 who Remote shell, computer name, command. pfink console Mar 16 17:58 ghe ttyp0 Mar 16 17:58 (slip-serv)
The remote shell runs in your home directory on the remote machine -
just the same as when you log in at home. To execute a command that is not
in your home directory, you must either give the path name relative
to your home directory or issue the cd command to change
the directory to it.
% rsh phy1 pwd Run pwd on phy1. /u/bohr In bohr's home directory with rsh.
Now bohr uses rsh to explore his home directory
% rsh phy1 ls -CF List in columns for remote phy1. Mail/ bin/ News/ proj/ % rsh phy1 ls -CF proj Look at the directory proj. bin/ src/ runs/ Note path is relative to home directory. % rsh phy1 ls -CF proj/bin Now look at remote subdirectory. calcL* bigjob* % rsh phy1 ls -CF /u/bohr/proj/bin Use full path name to get to the same directory. calcL* bigjob*
Now bohr wants to run one of his programs on phy1. To do this,
he has to change directory and then run his runs command.
While the change directory command cd and bohr's program
runs are separate commands, they must be concatenated as a
single command for rsh to execute. To do this, separate the
commands with a semicolon (the standard Unix procedure to run two
commands sequentially) and surround all of the commands with quotes:
% rsh phy1 "cd proj/runs; /u/bohr/proj/bin/calcL"
Or, you can
``escape'' the semicolon by placing a \ directly
% rsh phy1 cd proj/runs \ /u/bohr/proj/bin/calcL
The \ tells the shell not to place any special meaning on the next character and instead to just pass it along. In either case the remote shell gets the semicolon and interprets it as a command separator.
To really make use of someone else's resources, we may also need to
include I/O redirection in our remote commands. In this example bohr
runs a remote command with standard input from the file data.in, a file also located in the runs directory on the
remote machine. Since we again need to concatenate several commands,
the whole mess is enclosed in quotes:
% rsh phy1 "cd proj/runs; /u/bohr/proj/bin/job < data.in"
For another level of complication we can take the input file from our
local machine while running the command remotely:
% ls Local list. ch4.tex ch4.div ch4.ps What's on theo. % rsh phy1 lp -dps < ch4.ps Use local ch4.ps as input for the remote command.
Here we have printed a local file on a remote machine by running the lp -dps command on the remote machine with a redirected input from the local file ch4.ps.
The same methods work for output as well as input. Here bohr runs the
program remotely and directs the output to a local file:
% rsh phy1 /u/bohr/proj/bin/calcL > run1.out
In case you have different names on different machines, the rsh command accepts the same -l options as does rlogin.
So when bohr wants to run commands on phy2, he gives the
-l option to tell phy2 his login name is niels, not bohr:
% rsh phy2 -l niels who Remote command with different user id.