Shell script to roll new *.conf file

I have 27 aixservers and I want to add couple lines in my /etc/ntp.conf file. RSH is enabled in the enviroment. All the servers have the present conf file
root@aixserver14 # cat ntp.conf
#AIX Only /etc/ntp.conf:
# Updated NTP Conf for AIX Servers
# - rcvs updates from DNS:
#
disable auth
disable bclient
disable pll
disable monitor
server ntp1
logconfig =syncall +clockall
driftfile /var/log/ntp.drift
tracefile /var/log/ntp.trace

I want to add the below to the present configuration file
server ntp2
server ntp3
server ntp4

Before making any changes I want to back the file up and make necessary changes. So can anybody suggest.
jdenver247Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

TintinCommented:
I'm sure you've had the usual lectures about using ssh instead of rsh, so I won't go there.


#!/bin/sh
for host in `cat /file/with/hosts`
do
  rsh $host "cp /etc/ntp.conf /etc/ntp.conf.bak"
  rsh $host 'echo "server ntp2\nserver ntp3\nserver ntp4" >>/etc/ntp.conf'
done

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
woolmilkporcCommented:
Hi again,
part of the following you will already know from your last problem.
The same things I wrote there apply here, too.

wmp


#!/bin/ksh
for srv in $(cat ~/ntphosts)
do
ssh $srv \
     'cp -p /etc/ntp.conf /etc/ntp.conf.backup
      echo "server ntp2 \n server ntp3 \n server ntp4" >> /etc/ntp.conf'
done

Open in new window

0
woolmilkporcCommented:
Oh sorry,
this was an overlap!

Seems some people are too fast for me ...

wmp
0
jdenver247Author Commented:
Thanks both the codes are working
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Unix OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.