Using screen to monitor non-interactive scripts (or some other solution)

Posted by Michael on Server Fault See other posts from Server Fault or by Michael
Published on 2010-11-08T18:17:07Z Indexed on 2011/01/09 18:55 UTC
Read the original article Hit count: 170

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?

© Server Fault or respective owner

Related posts about linux

Related posts about monitoring