To simultaneously update password change in two server at a time

I am new beginner in Unix and little experienced in BaaN ERP.

Problem Statement: I have to run a BaaN session. I have to change the password for both primary and secondary server by using this session.

On primary server only few people has access permission (say 10). But on secondary server many people has login IDs (including those of primary one).

Requirement is that the user will run this session, which will prompt a Unix window to change the password. This will change the primary server password. But, this new password will should also get updated in the second server also. A user has same logind and password in both the servers. User do not want to re-enter password change for second server on a Unix Window.

Our Team is stuck at following point: We will write a shell script/BaaN code to connect to second server (telnet command). But how can we dynamically pass the two variables 'new password' and 'Re-enter new password' to update the password of second server; while I am changing password for the primary server.

I request you to please help me on this crucial matter for a crucial project. Also, please suggest any alternative on this problem either by today or tomorrow morning.

Thanking you in advance.

Existing Code in the BaaN session:
declaration:
table ttccom000 | Companies

before.program:
shell("passwd", SHELL_MWINDOW + SHELL_CONFIRM)
exit(0)

Above code opens a Terminal Emulator and asks user to enter existing password. It prompts the user to enter new password and reenter the new password. Then password for the current server is changed.