I have some autonomous scripts that run commands on remote machines over ssh. These scripts rely on getting stdout, stderr, and the return code of each command run. I want to be able to monitor the progress of the scripts on each target machine so that I can see if something has hung and possibly intervene if necessary.
My initial idea was to have the scripts run commands in a screen session, so that the person monitoring could simply attach to the session with
screen -x. However, it was hard to do that from a script since screen is an interactive program. I can send a command to the screen session with
screen -S session -X stuff "command^M", but then I don't get the output and return code that I need back.
My second idea was to put
script /path/to/log in
~/.bash_profile and log the entire session to a file. Then the monitoring person could simply tail the log file. However, this doesn't provide the interactivity that I was looking for.
Any ideas on how to solve this problem?