Howto get exit code of a script started in screen session

Posted by Bettina on Server Fault See other posts from Server Fault or by Bettina
Published on 2011-01-30T19:21:35Z Indexed on 2011/01/30 23:27 UTC
Read the original article Hit count: 195

Filed under:
|
|
|

Hi folks,

I am currently creating a backup script which uses screen to start a backup job with rsync inside a screen session. The backup jobs are started as follows.

screen -dmS backup /usr/bin/rsync ...

As soon as the rsync job is finished, the screen session is terminated automatically. To make sure, that the backup was successful, I would like to check the exit code of the rsync job but unfortunately I really don't know how to get the exit code after the screen was terminated.

Does someone have a good idea how to automatically check, if the rsync job was successful or not?

Would be great if someone does.

I already thought about using a temp file but like this:

screen -dmS myScreen "rsync -av ... ; echo $? > /tmp/myExitCode" but this unfortunately does not work. Then I thought about using stderr like in the example below:

screen -dmS myScreen "rsync -av ... >2 /tmp/rsync-sterr

None of my ideas worked out so far, since stderr is not written when I use the command above. :-( ?

Would be great if someone has a good idea or even a solution.

Cheers,

Bettina

© Server Fault or respective owner

Related posts about file

Related posts about screen