Sunday, 29 January 2012



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, Then the  remote  host’s  /etc/hosts  file  must contain a line     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 .  alpaprana

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
/home/ divya$ cat  .rhosts   bhaskar    ajay

/home/ajay$echo $HOME
/home/ ajay$ cat  .rhosts   bhaskar    ajay

And  entries  shown below   in  the remote host.

/home/ ajay$ cat  $HOME/.rhosts  ajay  divya

/home/bhaskar/ cat  $HOME/.rhosts  ajay  divya

After these changes are made, you can run the rsh command as shown in following examples.

Example 1)
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  “ls   inter*”
inter _college.txt

This runs the command  ‘ls  inter* ‘  in the remote host as user  ajay.
By default  it  runs  the   commands within double quotes  in user (ajay ) ‘s home directory defined by the  $HOME variable.

Example 2)
To run the commands   or process of a different   remote user

/home/ divya$ rsh  -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  -l   bhaskar  “ cd  Albumlist/old;  grep  -i  beatles  Film” .
Example 3)
you cannot use the environmental variables of the remote user directly inside rsh. For initializing all those variables run .profile

/home/ ajay$ rsh  -l   bhaskar   “ echo  $ORACLE_HOME; sqlplus /”
ksh: sqlplus  not found
 this did not work.
/home/ ajay$ rsh  -l   bhaskar   “. $HOME/.profile  1> /dev/null; echo  $ORACLE_HOME; sqlplus /”
/dev/null redirects  the standard output of running .profile to /dev/null.

No comments:

Post a Comment