0

I want to restart ntpd service on all remote machines so

All the machines are on amazon aws cloud.

So I wrote following script but while loop executes only once. Not getting exact issue.

ec2-describe-instances --filter "instance-state-name=running" --show-empty-fields | grep INSTANCE | awk '{print $18}'|sort > ntpd_restart_IP.txt

while read line
do
#echo ssh -i /mnt/keys/abc.pem root@$line /etc/init.d/ntpd restart
ssh -i /mnt/keys/abc.pem root@$line /etc/init.d/ntpd restart
done < ntpd_restart_IP.txt

Total 80 machines are there but it works only for first entry in ntpd_restart_IP.txt file.

innervoice
  • 120
  • 2
  • 13
  • 1
    First you can combine grep with awk like this: `awk '/INSTANCE/ {print $18}'`, then you should probably take a look at the file to see the syntax is correct. – Yaron Jul 27 '16 at 09:51
  • See [\[ this \]](http://unix.stackexchange.com/q/30400/25919). – sjsam Jul 27 '16 at 09:54
  • Did the `echo` you've commented out show you correct sequence of commands? – frist Jul 27 '16 at 11:58
  • http://unix.stackexchange.com/questions/107800/using-while-loop-to-ssh-to-multiple-servers – innervoice Jul 27 '16 at 16:28

0 Answers0