1

I've read lot of different links such as:

which all seem to say the same thing. I've tried most of the applicable options but have no clue what I'm doing wrong.

Currently I'm loading my scripts manually to not introduce any other issues possible.

Filename="startup.sh" - I create a screen on startup using an sh file containing:

#!/bin/sh
screen -dmS megadl

That works.

Filename="start.sh" - I create this file to load the detached screen and run another script.

#!/bin/sh
screen -r megadl /home/pi/mega_start.sh

It loads the screen, but nothing in mega_start.sh occurs.

Filename="mega_start.sh" - I create this file where the bulk of the code is. For testing purposes I only include echo for now.

#!/bin/sh
echo "test"

What am I doing wrong? it works up until I want start.sh to load up the mega_start.sh file.

0

for "what am I doing wrong" part, the answer is in the manual :)

-r resumes a detached screen session. No other options (except combinations with -d/-D) may be specified, though an optional prefix of [pid.]tty.host may be needed to distinguish between multiple detached screen sessions.

You can't do much while attaching to a session. So what can you do? You could use screen's stuff to put that command in the existing screen input queue and then attach to it (new line after the script is to actually execute it), start.sh:

#!/bin/sh
screen -S megadl -X stuff '/home/pi/mega_start.sh\n'
screen -r megadl

It is important to note that if you are already running something in that screen, you will pass it there, so it can be dangerous if you may be running something important:

$ screen -S test -X stuff 'top\n'  # run top

$ screen -r test  # top displaying processes

$ screen -S test -X stuff 'q'  # kill top
$ screen -r test  # top is no longer running

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.