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.
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.

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

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

Open in new window

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
Hi again,
part of the following you will already know from your last problem.
The same things I wrote there apply here, too.


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

Open in new window

Oh sorry,
this was an overlap!

Seems some people are too fast for me ...

jdenver247Author Commented:
Thanks both the codes are working
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.