Question

I have recently come across this post which says that it is possible to force a script to run in screen with a shebang. My question is, how does one do this if I want to reconnect to an existing screen session (and thus force the script to run under screen).

So, on my server, when I do screen -list, I see:

There is a screen on:
    22566.myscreen  (10/26/13 23:47:09) (Detached)
1 Socket in /var/run/screen/S-admin.

Now, I have the following bash script, and I would like the bash script to be run with the above screen session. At the moment, I have something like this:

#!/usr/bin/screen -r "myscreen" /bin/bash
# /home/foo/jobscripts/script.sh
#

echo $STY
git status
touch /home/foo/jobscripts/testsuccess.txt
exit 0

... but this obviously does not work and tells me Error: Unknown option r "myscreen" /bin/bash Wondering if there was a way to specify in shebang to reattach to my above screen.

Was it helpful?

Solution

For Linux, I think we should just use something like pid.sessionname.

For other Unix-like OS, it may also indicate the TTY like this pid.tty.sessionname.

To be sure, consult your manpage of screen : man screen

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top