Operating System - HP-UX
1833875 Members
3155 Online
110063 Solutions
New Discussion

Using remsh to append to remote hosts file.

 
SOLVED
Go to solution
Craig A. Sharp
Super Advisor

Using remsh to append to remote hosts file.

I am using a script to setup printers on remote servers. As standard procedure, the printer name and address is added to the hosts file on the remote machine.

In order to add the entry remotely, I have created a script that adds the printer address and name remotely via remsh.

Here is the line:

remsh $server echo $1 $2 >> /etc/hosts

The variables are as follows:

$server - the remote server name
$1 - the printer address
$2 - the printer name

On the local machine, if I execute the same line, it adds the entry to hosts correctly.

The statement executes on the remote and completes with no errors but when I look at the remote hosts file, there is no entry in the file.

I have tried the line outside of the script and the same problem exists. I am thinking that it is a permissions problem

The script is run as root and all other remsh commands in the script execute with correct results. This is the only line that is not functioning correctly.

FYI: the .rhosts file on each machine contain entries for the local and remote machines.

Thanks,

Craig A. Sharp
Roush Industries, Inc.
4 REPLIES 4
Vincenzo Restuccia
Honored Contributor
Solution

Re: Using remsh to append to remote hosts file.

remsh $server -n "echo $1 $2|tee -a /etc/hosts"

Thierry Poels_1
Honored Contributor

Re: Using remsh to append to remote hosts file.

hi,

remsh $server echo $1 $2 >> /etc/hosts
executes "echo $1 $2" on the remote server and redirects output to the local file.
You should pass the redirection instruction to the remote machine, try:

remsh $server "echo $1 $2 >> /etc/hosts"
This will execute "echo $1 $2 >> /etc/hosts" on the remote server.

good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
A. Clay Stephenson
Acclaimed Contributor

Re: Using remsh to append to remote hosts file.

Hi Craig:
You need to ">>" the output redirection; unquoted is taken to mean on the local host; quoted on the remote.

Clay
If it ain't broke, I can fix that.
Craig A. Sharp
Super Advisor

Re: Using remsh to append to remote hosts file.

Excellent answers. The script is now working correctly. Thanks for the assistance.

Craig