[SOLVED] Send command to another terminal and press enter
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I don't know squat about screen or tmux, but all the servers I've ever administered were headless. My only access has been via ssh (or telnet in the very old days)...so I don't agree. I think that nohup is the solution for the OP:
Code:
NAME
nohup - run a command immune to hangups, with output to a non-tty
SYNOPSIS
nohup COMMAND [ARG]...
DESCRIPTION
Run COMMAND, ignoring hangup signals.
so
Code:
nohup /path/to/script
By default, STDOUT is redirected to a nohup.out file, although the script can be redirected (>) normally. see man nohup
So,
ssh to server
login
nohup script
exit
The script will continue to run.
screen and tmux are also headless
nohup is not a solution for the OP if the script needs to display its output on a physical monitor.
One could make nohup work in that situation by using tail on the log
The problem with that is some(one|thing) needs to login on tty1 and tail said log.. back to square one.
nohup is not a solution for the OP if the script needs to display its output on a physical monitor.
One could make nohup work in that situation by using tail on the log
The problem with that is some(one|thing) needs to login on tty1 and tail said log.. back to square one.
I don't see a requirement to display output.
I see only that the OP wants to start a job and have it continue after they log out, but maybe I missed something.
Quote:
What i need is to connect remotely to that server over ssh (witch i already do) and insert the username and password so i can start a network script on it .
Basically my server is right next to me , i could do that by connecting my keyborad by usb to it and do all this stuff , but after i done i have to remove the keyboard from server to connect again into the machine i usually work .
Yes, I'm making the assumption that if there's no keyboard connected, there's also no monitor -- kind of the definition of headless
I'm sure they could also do what they want with tmux or screen, too, based on the posts here. As I said, I don't know those. Any of the three will do what I think they want to do. I could be wrong. It happens
Here it is the problem , i cant run the script over my ssh session because i will not be connected to the server much time , and when i disconnect my ssh session the script will stop . The script i want to run must be running on tty1 witch is the main display of the server .
What i need is to send username and password to server so the main tty session can start .
This is all i need here .
Note : If it was simple then i already had done it .
I could have miss-understood what that means
@pedropt
can you please confirm if you need the output of the script to be displayed on a dedicated screen that is attached to the machine running said script
Hi , all of you here replied but none of you understood what i need .
Lets be clear of 1 fact , my server is next to me , i just dont remove the login from boot because i have an ssh server running on the server and the server is connected to the web , despite the fact that my ssh port is obfuscated with massive protections on it .
So , i need the server normally asks username and password no matter if i connect to ssh remote connection , or if i simply plug my keyboard directly to it .
if i plug my keyboard to the server and manually insert the login and password , then after that i remotely can start whatever i need remotely using an ssh connection .
What i need is a way to make my login to the server terminal without unplug my keyboard from the machine i am working .
ttyecho almost did the job , i was able to isert the user login , but when i sent the password , always tells me "wrong password" , and is not that the password is wrong , i believe that there is any other issue there .
remotely using an ssh connection i can insert the login there by just typing on the remote shell
Quote:
echo "pedro" > /dev/tty1
and i can see "pedro" inserted on the login monitor , but i need to give an ENTER command so the server asks for password and then after that i can see my terminal opened on my server monitor and then start a cli script .
tmux is out of the question because what i want to run must be running on my server monitor and not on my ssh remote session .
So , for you all to understand the scenario just do this :
You have at your front 2 monitors from 2 different machines , 1 is your server and it is asking you the login .
The 2nd monitor is a remote shell to that server .
What i need is to send to server the login username and press "enter" , then after that i need to send the password for that login and press "Enter" again so the unlock shell can open on monitor 1 .
How to test using a VM
1st - logout from you gui session on your VM
2nd - press CTRL+ALT+F5 to get a terminal session
3rd - stop the services responsible for your gui login on VM (lightdm , slim , whatever)
4th - on you terminal session in VM write "logout"
after this point you are presented with a terminal session on your VM asking the login and then after that will ask you the password .
Now , using a remote shell connect to your VM and insert your login and password on the VM main display without doing it directly in it .
For test you can write on your remote shell (echo "test" > /dev/tty1) , and you will see diplayed on your login in VM the word test .
Now what i need is you to unlock your VM tty1 terminal remotely .
Note : The server is not asking the login from xorg or gui login , i just a normal terminal login .
I never realized that was possible to launch script on main terminal waiting for a login , but after i saw it working i realized that after all was possible to do it , and it have logic because i was connected as a root user over a shell .
Dont know if it is possible as a normal user to do that on the root tty , if it is then it will be a major vulnerabilty by the fact that someone can write a script to change permissions on their directory and can invoke it on tty1 .
I never realized that was possible to launch script on main terminal waiting for a login , but after i saw it working i realized that after all was possible to do it , and it have logic because i was connected as a root user over a shell .
Dont know if it is possible as a normal user to do that on the root tty , if it is then it will be a major vulnerabilty by the fact that someone can write a script to change permissions on their directory and can invoke it on tty1 .
The fact that the output is redirected to that tty does not change anything about permissions or abilities. Running the output on the "remote" (to the user) only changes where the results are displayed.
Note that the server is running things all the time with that "main terminal waiting for a login"
If you want the output to be the input for the other TTY then you'd need to play with ioctl in a script or small program to make it happen. In that way you could actually run the program on the other TTY, not just display the output.
Here's a script that does that, one which has been floating around the net in various forms for a while. I was unable to track down the original, though stackexchange had some in-depth examples, and have modified it also:
Code:
function sendtotty2() { perl -e 'open($tty,">","/dev/tty2"); ioctl($tty, 0x5412, $_) for (split("", join(" ", @ARGV))); close($tty)' "$@"; }
So, if you are already logged in somehow at TTY2, you can write to the input:
Code:
sudo sendtotty2 tmux new-session -s tty2 $'\n'
Then you can connect from your regular terminal and have tmux running on both your terminal and TTY2. Obviously anything running inside tmux will be visible in both places:
The console to which TTY2 is attached might be much larger than 80x24 so you'll have to resize your local terminal accordingly. Also, I've not figured out how to get that to work sending login credentials. I know too little about what's going on underneath.
Last edited by Turbocapitalist; 08-30-2019 at 02:37 AM.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.