0

I cannot find this anywhere on Google/SE, excuse me if it was just my wording.

I want to make screen do a command upon start. With pseudo code, doing

 screen -S SomeScreen -c SomeScript.sh

would make it execute SomeScript.sh automatically, without going into screen and typing this. Thanks!

(there is no tag for the screen command)

  • Can you explain a little bit more about "make screen do a command upon start"? – Radu Rădeanu Aug 17 '13 at 20:26
0

Look at the syntax in man screen:

screen [ -options ] [ cmd [ args ] ]

cmd is a command to run in the session. So, typing screen SomeScript.sh would make it execute SomeScript.sh automatically, without going into screen and typing this.

If you're looking for a way to have screen execute some command(s) every time you start a new session, I do it by putting them in ~/.screen-start and putting something like this at the end of .bashrc:

if [ -n "$STY" ]; then
  source ~/.screen-start
fi

Since screen sets $STY to the screen session identifier, you can test for whether it's set to know if screen is running. And since screen starts a login shell when invoked without a specific command, it will execute .bashrc.

There is probably a better way; I stopped looking since this worked well for me.

1

You can use the -X switch of screen (uppercase X, lowercase x means something else ;) ) to send a command to an existing screen session. So you can do something along the lines of

screen -md
screen -p 0 -X stuff $'echo "Test"\n'
screen -r

But I assume this doesn't fit your task of making things easier ;)

0

if you mean to carry out some execution at startup of the OS...

go to startup applications and add this command to the list there by selecting add.

You can get to startup applications by pressing the windows key and typing it in.

  • I meant to make it execute on screen start, but thanks for trying to help. – Ryan Aug 17 '13 at 20:01

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.