adding a host entry on another machine


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting adding a host entry on another machine
# 1  
Old 10-26-2006
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>

Code:
#!/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
# 2  
Old 10-26-2006
sorry forgot to mention, ive bee trying to create a string eg

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

but I still cant get the blasted thing to work Smilie
# 3  
Old 10-26-2006
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?
# 4  
Old 10-27-2006
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.
# 5  
Old 10-27-2006
thankyou , it works perfectly

Code:
#!/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 ?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Modifying/Adding in the DNS server entry using shell script

Dear Experts. I need to add/modify the entries in the DNS server and this has to be achieved using shell script and below is the requirement, could you please let me know if a shell script can be written for this task? 1. Log in to primary DNS server 2. Check /etc/named.conf if zone is... (4 Replies)
Discussion started by: VKIRUPHAKARAN
4 Replies

2. Shell Programming and Scripting

Host Machine not listed.

Hello everyone, I have a perl script to list all the host machines in my development environment. The script does various other tasks apart from listing the host names in an excel output. The problem is with the listing of host machines. The script lists all the host names except the host on which... (1 Reply)
Discussion started by: nmattam
1 Replies

3. UNIX for Dummies Questions & Answers

Host ID in Solaris Machine

Hi, On doing reinstallation of Solaris 10 OS, does an existing host id change? Regards, Thiru (1 Reply)
Discussion started by: nthiruvenkatam
1 Replies

4. Red Hat

Adding or deleting an entry in /etc/inittab without using vi editrors or any editor.

Hi masters Is there any way to edit or delete an entry in inittab file without using vi or any editors? We can use commands instead or any shell script .. If any one can help deeply appreciated Thanks a lot sai (3 Replies)
Discussion started by: saidiya
3 Replies

5. UNIX for Dummies Questions & Answers

Cannot ssh into machine although it has entry in authorized keys

We rebooted one our servers, call it server A, and now it cannot ssh into another machine, call it server B. We have the server A's ssh signature in server B's authorized key. I tried to manually generate the a new key using ssh-keygen command but the key looks nothing like the old key: It has... (10 Replies)
Discussion started by: mojoman
10 Replies

6. Solaris

How to get the IP address / Host name of client machine

Hi How to get the IP address / Host name of a particular user connected to Unix Server. For example: If used 'DevUser1' is connected to Unix server. I need to find out from which PC this connection has been made. How can this be achieved? Thanks (6 Replies)
Discussion started by: MVL
6 Replies

7. Solaris

etc host entry problem

Dear Members, My app server is running in sun solaris. When i am trying to invoke another application running in a different m/c by calling its ip aa.bb.cc.dd , i am succeeding. But, when i maintain the same ip in etc host and try to invoke the application using the host name, it is failing.... (5 Replies)
Discussion started by: kandanathan
5 Replies

8. HP-UX

Adding printer entry into host file

Hi relatively new to unix so sorry if this is a stupid question: How do i add a printer entry into the host file. I know how to add the printer using sam, but i am required to add the host file entry into /etc/hosts which i am unaware of how to do. Any help would be greatly appreciated. (2 Replies)
Discussion started by: Wade Gava
2 Replies

9. Linux

problem in adding an extra entry in a dir:fuse imlementation

Well the problem comes when i try to add an extra file into the existing filesystem mounted at some mountpoint containing a single file hello. suppose i add a file say "TANVIR"(c it on d line next to line no:49) , it gives me abnormal results...... like 1)d file can't be opened 2)no file... (0 Replies)
Discussion started by: Tanvirk
0 Replies

10. Shell Programming and Scripting

Adding entry into crontab in ksh program

Hi falks, I have the following ksh function ,which adding entry to crontab during ksh program running: { print "Go\c" >/dev/null 2>&1 print '0 0 * * * su - ias -c "/home/orca/core-${SCHEMA_NAME}/CLI/cleanup_BRMS.ksh"\c' >/dev/null 2>&1 print "\033:wq!" >/dev/null 2>&1 } | \crontab -e... (2 Replies)
Discussion started by: nir_s
2 Replies
Login or Register to Ask a Question