adding a host entry on another machine

I have written this small script to add an entry to a remote /etc/hosts file which needs to be run from our central admin box and is passed one parameter $1 <hostname>

#!/bin/ksh
echo "Which host entry would you like to add to $1"
read host_to_add
echo "what is the IP address?"
read ip

echo "Adding $host_to_add $ip to $1"
ssh $1 'echo $host_to_add $ip >> /etc/hosts'

but obviously this doesnt work because the variables arent passed over when issuing the ssh statement at the end there, so what i actually get in the target machines host file is a blank line at the end

Does anybody have an idea on how I can get around this???

Cheers

sorry forgot to mention, ive bee trying to create a string eg

string= "$1 'echo $host_to_add $ip >> /etc/hosts'"
ssh $string

but I still cant get the blasted thing to work :mad:

ssh $1 "echo $host_to_add $ip >> /etc/hosts"

That should put it in there - the only issue may be the order. Doesn't the IP come first in /etc/hosts?

After changing the /etc/hosts file, check the /etc/inet/hosts file too...

it may not get affected in hosts file after restart the server so check the /etc/hosts file after restarting the server.

in this situation /etc/inet/hosts file to be changed accordingly.

thankyou , it works perfectly

#!/bin/ksh

if [ $# -ne 1 ]; then

        echo usage: "./add_a_host <hostname>"
        exit
fi


ping $1 2 > /dev/null

if [ $? != 0 ] ; then
        echo " "
        echo "Couldn't ping $1, cannot proceed with script"
        exit
else


echo "Which host entry would you like to add to $1"
read host_to_add
echo "what is the IP address?"
read ip

echo "Adding $host_to_add $ip to $1"

ssh $1 "echo $ip $host_to_add  >> /etc/hosts"


fi

Does anybody know any ways I can pretty it up a little ?