help needed with shell script to append to the end of a specific line in a file on multiple servers

Hi Folks,

I was given a task to append three IP's at the end of a specific (and unique) line within a file on multiple servers.

I was not able to do that with the help of a script. All I could was:

for i in server1 server2 server3 server4
do
ssh $i
done

I know 'sed' could be used to append to the end of the line but how to save that and replicate on all servers in the list?

Original File
-----------

#cat /etc/ftpd/ftpaccess
greeting brief
log commands
log transfers
class users real 172.25.6.148 172.25.197.148 172.25.52.100 172.21.56.75 172.21.54.159 172.25.2.25 172.25.2.26 172.25.119.132 172.25.119.133 172.25.119.134 172.25.119.135 172.25.183.132 172.25.183.133 172.25.183.134 172.25.183.135
banner /etc/ftpd/banner.txt

(each server had different IP's in the line starting with: class
users real .....):

Change required:
----------------

Append "172.21.105.99 172.21.105.100 172.21.105.101" at the end of line starting with text:'class users real')

Any help will be appreciating in how would you gurus would accomplish this task with the help of a script / scripted-command.

Thanks in advance

Not sure I understand, but this might work if I do.

for i in server1 server2 server3 server4; do
    ssh $i "sed -i 's/\$/ 172.21.105.99 172.21.105.100 172.21.105.101/' file.txt"
done

Note: the backslash protects the dollar sign from the local shell. When it arrives on the remote server, it's in single quotes. The double quotes and backslash have been removed.

this will append the ip address in all the lines.

Oops. I left off the address.

for i in server1 server2 server3 server4; do
    ssh $i "sed -i '/class users/s/\$/ 172.21.105.99 172.21.105.100 172.21.105.101/' file.txt"
done
ssh $i "sed -i ' /^class users real/ s/\$/ 172.21.105.99 172.21.105.100 172.21.105.101/' file.txt"

Thanks for both the replies and making it work for me!
Salute! :b: