Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a server with several screens running, each with their own node server listing to different ports. I'd like to create Jenkins jobs to ssh into the box, reattach a specific screen, stop the process, pull from git, restart the app, and detach the screen. Can you 'stuff' a Ctrl+C into a screen? Thinking something along the lines of:

ssh myuser@myserver "screen -S 1234.myscreen -X stuff '[[Ctrl+C]] && git pull origin master && npm install && node app' [[Detach screen]]"
share|improve this question

migrated from Mar 15 '13 at 1:40

This question came from our site for professional and enthusiast programmers.

up vote 2 down vote accepted

Ctrl+C sends a SIGINT. So if you can determine the PID of the process you want to signal, you can do kill -INT pid before the git pull, or killall -INT processname if you want to stop them all, assuming your killall does not behave like killall5.

As for scripting the detachment of a screen session, I've no idea. Perhaps someone else can help you there.

EDIT: It just occured to me that you don't need to script the detachment or indeed do anything with screen. Simply execute something like this inside screen:

while sleep 1; do
    ./some_program      # which saves its PID to a pidfile
    git pull

And then you can execute this from outside screen, over ssh:

kill -INT $(cat pidfile)

If your process does not save a pidfile, you can try to use start-stop-daemon to have it do that:

start-stop-daemon --start --exec ./some_program --pidfile pidfile --make-pidfile
share|improve this answer
This put me on the right track. I ended up using upstart scripts. – swider Mar 18 '13 at 20:24

The Ctrl+C sequence must be entered as a literal ^C character:
Ctrl+V (allows insertion of a literal character), then Ctrl+C

When the stuff command is used screen doesn't interactively attach the session so it isn't necessary to detach. You may, however, need a carriage return after the last command, entered as a literal:
Ctrl+V Ctrl+M

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.