TCP/IP DOS Utilities

Executing Commands on a Remote Host

Part 6/9

Previous:    Printing Files on Remote Printers

Next:    Setting up your Workstation as a File Server

Executing Commands on a Remote Host

The LAN WorkPlace® utilities include two utilities to execute your commands on a remote host. The Remote Shell (RSH) utility executes your command on a remote operating system without requiring a password. The REXEC utility executes your command on a remote operating system after you supply the required password for the remote host.

These utilities cannot execute interactive commands (such as the UNIX® commands more and vi). To execute interactive commands, use the TNVT220 utility.

For you to execute remote commands, the remote host must be running either the RSH or REXEC server programs. The RSH server program is called rshd on UNIX hosts; the REXEC server program is called rexecd on UNIX hosts.

Both the RSH and REXEC utilities also require that your workstation and the remote host list each other in their respective HOSTS or hostname database files. Your workstation accesses the DNS name server or the file HOSTS in the \NET\TCP directory; the remote host accesses either the DNS name server or its host table. The host table for UNIX is /etc/hosts.

Although RSH does not require that you enter a password, it does require that either of the following conditions be met:

Do not enable the hosts.equiv file for access authorization, because your workstation does not have a secure authorization mechanism. Use the .rhosts mechanism. If access authorization is a serious issue, use FTP to transfer files, TNVT220 to operate remote hosts, and REXEC to execute remote commands.

If you set your local username to root, the server does not use the hosts.equiv file to validate you on the remote host. Instead, it uses the .rhosts mechanism.


Using RSH

You can execute a remote operating system command by using the RSH command in the following format:

RSH remote_host [ -L remote_user ] [ -A { L | R | B}]
   [ -B { L | R | B }] [ -N ] command [ argument [...]]

The following table describes the RSH command-line options and parameters.

RSH Options and Parameters
Options and Parameters Description
remote_host This parameter specifies the name of the remote host on which you want to execute command.
-L remote_user This option and parameter log in to remote_host as the user remote_user.
For UNIX systems, there must be an entry for remote_user in the .rhosts file on the remote host. You must specify remote_user as it is listed in the remote host hosts.equiv or .rhosts file. Your workstation must also be listed in the /etc/ hosts file on the remote host.
-A { L | R | B }  This option transfers data in ASCII format when redirecting input to or output from a command. This option is useful only if you are redirecting the input or output of the command specified on the RSH command line. Include an L, R, or B to specify the origin of the data you are sending.
Include an L (local) to send standard input from your workstation to the remote host in ASCII format.
Include an R (remote) to send standard output and standard error from the remote host to your workstation in ASCII format.
Include a B (both local and remote) to transfer data between your workstation and a remote host in ASCII format.
Do not use the -A option if you are executing a command remotely or transferring text to a UNIX system.
-B { L | R | B }  This option transfers data in binary (nontext) format. If you omit the -B option, RSH transfers data in ASCII format. Include an L, R, or B to specify the origin of the data you are sending.
Include an L (local) to send standard input from your workstation to the remote host in binary format. Your workstation does not translate end-of-line (EOL) characters when it detects a line-feed character (0A Hex) in your data stream.
Include an R (remote) to send standard output and standard errors from the remote host to your workstation in binary format. This option has no effect if the remote host is running UNIX.
Include a B (both local and remote) to transfer files between your workstation and a remote host in binary format.
-B This option redirects standard input to the NUL: device. If the remote application tries to read from standard input, it should get an end-of-file condition.
command  This parameter specifies the command you want to execute on the remote host. You can specify a single command or a series of commands. 
argument  This parameter specifies required or optional arguments associated with each command.

For example, to execute operating system commands on a UNIX host (finance) and a VMS host (SALES), type the following commands:

RSH finance ls -lg /x/accounts <Enter>RSH SALES SHOW TIME <Enter>

You execute a command using a remote account other than your own by specifying the -L option. For example, you can print the past_due file from the receivables account on the UNIX host finance by entering the following command at your workstation:

RSH finance -L receivables lpr past_due <Enter>

The following example shows how to include the RSH command in a DOS batch file. This file formats a DOS text file on a UNIX host and prints it on a DOS printer. The remote UNIX host is called remotehost. When you run this file you specify an input filename by entering the PAGEPR command in the following format:

PAGEPR <filename> <Enter>

Example 6-1 shows how you can create a batch file that uses the RSH utility to list the files on the unix1 host and redirect the list to the contents file:

Batch File That Uses the RSH Utility

@ECHO OFF
REM LISTS FILES ON REMOTE HOST UNIX1 AND PIPES OUTPUT TO A CONTENTS FILE
REM ON REMOTE HOST
RSH UNIX1 ls -lt !] contents


Using REXEC

You can use the REXEC utility to execute a command on a remote host running the REXEC server (rexecd on a UNIX host).

To execute a remote operating system command with the REXEC utility, you use the RSH command in the following format:

REXEC remote_host [ -L remote_user ] [ -N ] command [argument [...]]

Before REXEC executes your command, you must enter a password for the remote account.

The following table describes the REXEC command-line options and parameters.

REXEC Options and Parameters
Options and Parameters  Description 
remote_host  This parameter specifies the name of the remote host on which you are executing command. 
-L remote_user  This option and parameter log in to remote_host as the user remote_user. 
-N  This option redirects standard input (usually from your keyboard) to the NUL: device. If the remote application tries to read from standard input, it should get an end-of-file condition. 
command  This parameter specifies the command you want to execute on the remote host. It can include options and parameters. If the operating system running on the remote host is case sensitive, as is UNIX, you must type command in the appropriate case. 
argument  This parameter specifies any required or optional arguments associated with command.

For example, to execute commands on a UNIX host (finance) and a VMS host (SALES) with the REXEC, type the following commands:

REXEC finance ls -lg /x/accounts <Enter>
REXEC SALES DIR/SIZE DUA0:[MARCH] <Enter>

The REXEC utility prompts you for a password before executing the command.

You can also execute a command using an account other than your own by specifying the -L option. For example, you could print the past_due file from the receivables account on the UNIX host finance by typing the following command:

REXEC finance -L receivables lpr past_due <Enter>

REXEC prompts you for the password of the account you are using.

Password (finance:receivables):

REXEC normally terminates when the remote command concludes. However, you can abort this command during its execution by pressing either <Ctrl>+<C> or <Ctrl>+<Break>.


Redirecting Input and Output for the RSH and REXEC Commands

You can redirect an input file from your workstation to remote commands when you use the RSH and REXEC utilities. You can also redirect the output of the remote commands to a file using the metacharacters described in Table 6-3.

DOS and Equivalent RSH/REXEC Metacharacters
Metacharacter  Metacharacter Type  Meaning 
> DOS  This metacharacter redirects standard output to a local file. 
>> DOS  This metacharacter appends standard output to a local file. 
< DOS  This metacharacter redirects standard input from a local file. 
DOS  This metacharacter redirects the output from one command to the input used by the next command. 
! ]  RSH or REXEC  This metacharacter redirects standard output to a remote file. 
! ] ]  RSH or REXEC  This metacharacter appends standard output to a remote host file. 
! [  RSH or REXEC  This metacharacter redirects standard input from a remote host file. 
! #  RSH or REXEC  This metacharacter redirects the output from one command to the input used by the next command.

The RSH and REXEC utilities send your remote commands intact to the remote host, except for any metacharacters you include with the commands. If you include metacharacters in the RSH or REXEC command line, they are interpreted by DOS. The RSH and REXEC utilities assume that the name you specify to the right of the metacharacter specifies a file on your workstation.


Using DOS Metacharacters

The DOS metacharacters cause your DOS workstation to redirect input from local input or output files. The following examples show how to use these characters:

You can redirect a local file as the input for a remote command by typing one of the following commands:

RSH remote_host command < local_file <Enter>

REXEC remote_host command < local_file <Enter>

The REXEC command interprets the first line of local_file as the password the remote host requires in order to execute your command.

You can redirect the output from a remote command to a local file by typing one of the following commands:

RSH remote_host command >> local_file <Enter>

REXEC remote_host command >> local_file <Enter>

You can append the output of a remote command to a local file by typing one of the following commands:

RSH remote_host cat file1 >> file2 <Enter>

REXEC remote_host cat file1 >> file2 <Enter>

You can redirect the output of one remote command to be the input used by another remote command by typing one of the following commands:

RSH remote_host command | command <Enter>

REXEC remote_host command | command <Enter>

The remote host operating system can use metacharacters differently than DOS. If you want the remote host to interpret these metacharacters, enclose the redirected part of the command in quotation marks (" "). This causes the host to redirect input and output.


Using RSH and REXEC Metacharacters

RSH and REXEC recognize additional metacharacters that DOS ignores but UNIX interprets. The RSH and REXEC metacharacters, like the DOS metacharacters used with quotes, cause the host to redirect input files to your command or output from your command to a remote file. The following examples show how to use these metacharacters:

You can redirect a remote file to provide the input used by a remote command by typing one of the following commands:

RSH remote_host command "< remote_file" <Enter>

REXEC remote_host command "< remote_file" <Enter>
RSH remote_host command ![ remote_file <Enter>
REXEC remote_host command ![ remote_file <Enter>

You can redirect the output of a remote command to a remote file by typing one of the following commands:

RSH remote_host command "< remote_file" <Enter>

REXEC remote_host command "< remote_file" <Enter>
RSH remote_host command !] remote_file <Enter>
REXEC remote_host command !] remote_file <Enter>

You can append the output of a remote command to a remote file by typing one of the following commands:

RSH remote_host command "<< remote_file" <Enter>

REXEC remote_host command "<< remote_file" <Enter>
RSH remote_host command !]] remote_file <Enter>
REXEC remote_host command !]] remote_file <Enter>

If you must include an exclamation point (!) that is not part of a metacharacter, type two exclamation points (!!). RSH and REXEC interpret this as a single exclamation point.

You can have the remote host redirect the output of one remote command to the input used by another remote command by typing one of the following commands:

RSH remote_host command "| command" <Enter>

REXEC remote_host command "| command" <Enter>
RSH remote_host command !# command <Enter>
REXEC remote_host command !# command <Enter>


Examples of How to Use Metacharacters

The following examples show how you can use the above formats to redirect input and output. Some of these examples show how to substitute a remote command and its parameters for the command variable. Other examples show how to combine multiple metacharacters in an RSH or REXEC command.

You can execute the UNIX date command on the remote host finance and have your workstation redirect the output to the DATEFILE.TXT file on your workstation:

RSH finance date > DATEFILE.TXT <Enter>

REXEC finance date > DATEFILE.TXT <Enter>

RSH and REXEC create or overwrite the DATEFILE.TXT file. REXEC waits for you to type the password you use on the remote host before it executes the date command.

You can execute the UNIX date command on the remote host finance and have the remote host redirect the output to the datefile file on the remote host.

RSH finance "date > datefile" <Enter>

REXEC finance "date > datefile" <Enter>
RSH finance date !] datefile <Enter>
REXEC finance date !] datefile <Enter>

You can execute the UNIX cat command on the remote file earnings (on the remote host finance), pipe the output of the cat command to the UNIX grep command, and redirect the output of the grep command to the remote file quarter3:

RSH finance "cat earnings|grep July > quarter3"<Enter>

REXEC finance "cat earnings|grep July >quarter3" <Enter>
RSH finance cat ![ earnings !# grep July !]]quarter3 <Enter>
REXEC finance cat ![ earnings !# grep July !]]quarter3 <Enter>

You can execute the UNIX date command on the remote host finance and append the output to the datefile remote file.

RSH finance "date >> datefile" <Enter>

REXEC finance "date >> datefile" <Enter>
RSH finance date !]] datefile <Enter>
REXEC finance date !]] datefile <Enter> 

 

Top    

Previous:    Printing Files on Remote Printers

Next:    Setting up your Workstation as a File Server