This can be rather fragile and may not actually work as expected, as we've seen above. I'd recommend refactoring this step to get the actual position from both master and slave via direct query to each and print that out instead of relying on ps output piped through three different commands.
This may not exactly match in all cases. Looking at the code, it's relying on awk to figure out the position of where each item is:
This can be rather fragile and may not actually work as expected, as we've seen above. I'd recommend refactoring this step to get the actual position from both master and slave via direct query to each and print that out instead of relying on ps output piped through three different commands.