Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending ctrl-c to specific screen session

I am designing a script to launch a process inside a named screen session.

as_user "screen -p 0 -S **$command** -X eval 'stuff \"wine LFS.exe /cfg=**$command**.cfg\"\015'"

So bash myscript.sh start test will create a screen named test and run the test.cfg with the software.

Now I want my script to access the specific screen session and do a CTRL+C to stop the running process so i can kill the screen session.

Something like this:

as_user "screen -p 0 -S **$command** **... kill the process with ctrl-c...**"
as_user "screen -p 0 -S **$command** -X eval 'stuff \"exit\"\015'"
like image 662
user2280032 Avatar asked Apr 14 '13 16:04

user2280032


People also ask

How do I change my screen session?

ctrl + a , c will create a new "window" in your active screen session. You can switch between multiple windows (as Ansgar indicated) with ctrl + a , n for the next window, and ctrl + a , p for the previous window. ctrl + a , " will give you a list of all your open windows.

How do I create a screen session in Linux?

Starting Linux Screen Press Space to continue to the next page. Press Space again to open a new screen session. The system drops out to a command line that looks just like a regular terminal window. The manage screen shells, use Screen keystrokes (in most cases, Ctrl + a, followed by another key).


Video Answer


1 Answers

I don't quite understand you but to send ctrl-c to a window in a screen session:

screen -S session_name -X at window_number stuff $'\003'
# or
screen -S session_name -X -p window_number stuff $'\003'

If you want to send something to all the windows, use # (needs to be quoted) as the window_number.

UPDATE:

Screen's stuff command also supports ^X (or ^x) to mean CTRL-X so the following command can also be used to send CTRL-C.

# Here '^C' is two chars, '^' and 'C'
screen -S session_name -X at window_number stuff '^C'
like image 153
pynexj Avatar answered Sep 22 '22 08:09

pynexj