Sunday, August 29, 2004

SSH Continued

Coming back to what we left yesterday night was utilizing the the ssh agent to push updated file like /etc/resolv.conf or /etc/ntp.conf across a list of servers.

Its much better than logging into each server and modifying them .

Say i have a list of 100 servers in a file called /home/nitin/list.

#more /home/nitin/list
server1.mydomain.com

server2.mydomain.com
server3.mydomain.com
server4.mydomain.com
and so on till server 100 server name.
Here is a simple script which would replace the existing /etc/ntp.conf with the file i updated as /home/nitin/ntp.conf
I am assuming that you have your rsa or dsa key on all the 100 servers and also you are comfortable with using the ssh-agent utility.
Last but not the least you know the scp utility and also have superuser privilidges on the machines you want to replace the file on.;
The script reads as :
#for i in `cat list` ;do scp /home/nitin/ntp.conf nitin@$i:/etc/ntp.conf; done
Thats it no manual intervention needed and also just run the script watch the fun.
Another stuff you can do is if u want to run certain commands like check disk usage for all servers what you can do is :
#for i in `cat list` ;do ssh nitin@$i df -h; done
The other very good utility is rsync : http://rsync.samba.org/
This is how you do it :
#rsync -a -e ssh /home/nitin/ntp.conf nitin@remotemachine.com:/etc/ntp.conf
Here it is important to use the -e ssh so that rsync uses the ssh portocol to sync files rather than rcp.
I guess that makes life a lot more easy for sysad's handling more than 500 servers and needing to push stuff.
If some one's got a better method pls put it here would help a lot of us.
adiew
Nitin :)

0 Comments:

Post a Comment

<< Home