I have this setup where I have computer with ssh and a display where I have a user logged in to terminal. What I want to do is send commands like I was using that local session with keyboard. I tried to echo to /dev/tty1 but it just shows what I typed instead executing it. Which makes sense. The system only has bash so no GUI or anything like that.
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
The TIOCSTI ioctl can inject characters into a terminal, or see instead uinput on Linux to generate keyboard (or mouse!) input.
ttywrite.c– sample C implementation-
Term::TtyWrite– Perl implementation$ sudo perl -MTerm::TtyWrite -e 'Term::TtyWrite->new("/dev/pts/2")->write("echo hin")'
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0