Howto get exit code of a script started in screen session
- by Bettina
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