0

I am attempting to start a screen session in detached mode over SSH that executes a bash command inside screen...

#!/bin/bash
set -e

ssh jlroberts@10.0.0.202 "screen -wipe"

sleep 1

ssh jlroberts@10.0.0.202 screen -dmS session1 bash -c 'weechat --dir ircdir'

sleep 1

ssh jlroberts@10.0.0.202 -t "screen -x session1"

however, the following line does not seem to be working in the script, however, it works from the command prompt, any ideas?

ssh jlroberts@10.0.0.202 screen -dmS session1 bash -c 'weechat --dir ircdir'
1

I believe the set -e together with ssh jlroberts@10.0.0.202 "screen -wipe" is the issue.

If there is no screen session ssh jlroberts@10.0.0.202 "screen -wipe" will fail and return exit code 1.

Then, when set -e is set it means the script will exit immediately on a non-zero status.
Bash - set

I think either:

  • skip exit on non-zero status, I.e change the 'set -e'
  • make sure that there is a screen session available before you run the script
  • skip the screen -wipe
  • other solution that match your requirements

For debug and trying you can temporary change set -e to set -ex.
Then you will see that the script will never comes to this row.
ssh jlroberts@10.0.0.202 screen -dmS session1 bash -c 'weechat --dir ircdir'

Additionally, as test to make it run, change set -e to set -x.
Then you will see it run and ssh jlroberts@10.0.0.202 screen -dmS session1 bash -c 'weechat --dir ircdir' will be in the debug message.

| improve this answer | |
  • oh that makes a lot of sense, I have set -e and set -x confused... – Jeffrey L. Roberts Oct 7 at 18:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.