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 and send a newline character.
(Yes, the second
" must be in a new line, otherwise you would just send the text and have to press return in the screen session. Alternatively, use
To do this, you will need to have write access to
user2/sessionname; read screen's manual page for description of
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
/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
>& file is equivalent to
> file 2>&1, which redirects both stdout and stderr to the given file.)