rsh
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.
Prerequisites
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 158.0.125.23, Then the remote host’s /etc/hosts file must contain a line
158.0.125.23 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 158.0.125.45 .
158.0.125.45 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
mahaprana
/home/ divya$ echo $HOME
/home/ divya
/home/ divya$ cat .rhosts
158.0.125.45 bhaskar
158.0.125.45 ajay
/home/ajay$echo $HOME
/home/ajay
/home/ ajay$ cat .rhosts
158.0.125.45 bhaskar
158.0.125.45 ajay
And entries shown below in the remote host.
/home/ajay$hostname
alpaprana
/home/ ajay$ cat $HOME/.rhosts
158.0.125.23 ajay
158.0.125.23 divya
/home/bhaskar/ cat $HOME/.rhosts
158.0.125.23 ajay
158.0.125.23 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
ajay
/home/ ajay$ rsh 158.0.125.45 “ls inter*”
interbranch.csv.gz
interschool.csv.gz
inter _college.txt
inter-dept.lst
This runs the command ‘ls inter* ‘ in the remote host 158.0.125.45 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 158.0.125.45 -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 158.0.125.45 -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 158.0.125.45 -l bhaskar “ echo $ORACLE_HOME; sqlplus /”
ksh: sqlplus not found
this did not work.
/home/ ajay$ rsh 158.0.125.45 -l bhaskar “. $HOME/.profile 1> /dev/null; echo $ORACLE_HOME; sqlplus /”
/oracle/app/product
SQL>
/dev/null redirects the standard output of running .profile to /dev/null.
No comments:
Post a Comment