Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a command inside a screen session

I would like to know how to execute a command inside a screen session. i searched and I found this :

screen -S nameofscreen -X stuff "command"

When I type this, the command is typed inside the screen but it is not executed. So my queston is how to press enter using this command.

like image 932
Babajaga Avatar asked Dec 20 '22 01:12

Babajaga


1 Answers

I'd do something like this:

screen -S sessionName bash -c 'cmd; exec bash'

it starts a new session executes cmd and launches shell (otherwise it'd drop that new session).

-X will allow you to send input to a specified session -- that's why your command didn't execute. To execute it you'd need to add enter sign like Paul suggested. It can be done with Ctrl+v and then Enter. That will produce that ^M. So:

screen -S sessionName -X stuff 'cmd^M'

That, in itself, won't however attach a detached session.

like image 160
guessimtoolate Avatar answered Jan 11 '23 04:01

guessimtoolate