Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have two users; user1 and user2. I have a bash script run by user1, that needs to run a command on a screen terminal started by user2. Suggestions? Thanks Max

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Do you want it to look as if user2 typed the command?

In the case of screen, you can use

screen -S user2/sessionname -p windowname -X "stuff ~user1/somescript.sh

This will type the text ~user1/somescript.sh (referring to a file in user1's home directory) to a specific window of the given screen session.

(Yes, the second " must be in a new line. Alternatively, use $'stuff blah\n')

To do this, you will need to have write access to user2/sessionname; read screen's manual page for description of multiuser and acladd.

In the generic "run stuff on another tty" case, you can use writevt /dev/pts/X sometext; the writevt tool is part of console-tools package. If your distro uses kbd instead, get writevt.c. This is specific to Linux.

Or do you just want user2 to see the output?

./somescript.sh >& /dev/pts/X

where /dev/pts/X is the tty device that belongs to user2's screen.

You will need write access; this can be given by user2 with chmod/setfacl, or you can use sudo.

(>& file is equivalent to > file 2>&1, which redirects both stdout and stderr to the given file.)

share|improve this answer
Thanks for the answer; to clarify, I need to accomplish the first goal (look as if user2 typed the command). What is the difference between screenname, and windowname? I looked through the man page for screen, but couldn't find anything. Thanks –  mazzzzz Mar 22 '11 at 23:02
@mazzzzz: A user may have multiple 'screen' sessions (I think I should have used sessionname rather than screenname). Each session can have multiple windows. (Having multiple windows displayed in a tiled layout is common: C-a :split) –  grawity Mar 23 '11 at 0:19
And if you only have one window, what would its name be? Does it have a default name, or do I need to find it somewhere? –  mazzzzz Mar 23 '11 at 0:57
@mazzzzz: Just skip the -p option. –  grawity Mar 23 '11 at 5:28
Don't know if this is the best practice, but it works :) Start the webhost user, then run a screen in there, then su into the server user, then run the server. Haha, there is something wrong with that. Thanks for the help (and if you have a better way to set it up, I'm all ears) –  mazzzzz Mar 26 '11 at 4:04

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.