rsh is used to execute commands on a remote machine.
The rsh command executes the command or a program in another host from current working machine without having to login into that remote machine by entering a password as in ssh. You can run any unix command, or a shell script of a remote host.
rsh command cannot be executed without making these changes.
1) make a list of the users of both the local and remote hosts and their $LOGNAME s who are going to use rsh to run commands or scripts.
2)Open the required ports which is going to be used for rsh and rcp.
3)make an entry of remote host in /etc/hosts file of the local host and an entry of local host in /etc/hosts of the remote host. This change can done my root user,if you do not have root access then contact your unix admin.
A sample entry is as shown, assume that your hostname is mahaprana and the IP address is 18.104.22.168, Then the remote host’s /etc/hosts file must contain a line
22.214.171.124 mahaprana #backup server.
the comments (3rd column) is optional.
Similarly make an entry of remote host In /etc/hosts file of local host. If remote hostname is alpaprana and its IP address is 126.96.36.199 .
4)The list of users are to be placed in $HOME/.rhosts file of both local and remote hosts for every user.
Eg: If the local users are divya and ajay and remote users are bhaskar and ajay.
Make entries as shown for respective users in local host
/home/ divya$ hostname
/home/ divya$ echo $HOME
/home/ divya$ cat .rhosts
/home/ ajay$ cat .rhosts
And entries shown below in the remote host.
/home/ ajay$ cat $HOME/.rhosts
/home/bhaskar/ cat $HOME/.rhosts
After these changes are made, you can run the rsh command as shown in following examples.
Suppose you are working as a user in local host and the local and remote users are same.
/home/ ajay$ echo $LOGNAME
/home/ ajay$ rsh 188.8.131.52 “ls inter*”
This runs the command ‘ls inter* ‘ in the remote host 184.108.40.206 as user ajay.
By default it runs the commands within double quotes in user (ajay ) ‘s home directory defined by the $HOME variable.
To run the commands or process of a different remote user
/home/ divya$ rsh 220.127.116.11 -l bhaskar “ grep -i beatles Albumlist/old/Film ”
Here comes the sun - BEATLES
Beatles-Twist and shout
To run multiple commands in the remote host use semicolon to separate them.
Eg: If you want to run the above command by making your working directory as Albumlist/old
rsh 18.104.22.168 -l bhaskar “ cd Albumlist/old; grep -i beatles Film” .
you cannot use the environmental variables of the remote user directly inside rsh. For initializing all those variables run .profile
/home/ ajay$ rsh 22.214.171.124 -l bhaskar “ echo $ORACLE_HOME; sqlplus /”
ksh: sqlplus not found
this did not work.
/home/ ajay$ rsh 126.96.36.199 -l bhaskar “. $HOME/.profile 1> /dev/null; echo $ORACLE_HOME; sqlplus /”
/dev/null redirects the standard output of running .profile to /dev/null.