LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-28-2019, 05:17 AM   #16
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 1,992

Rep: Reputation: 549Reputation: 549Reputation: 549Reputation: 549Reputation: 549Reputation: 549

Quote:
Originally Posted by scasey View Post
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.
 
Old 08-28-2019, 01:07 PM   #17
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.6
Posts: 3,635

Rep: Reputation: 1205Reputation: 1205Reputation: 1205Reputation: 1205Reputation: 1205Reputation: 1205Reputation: 1205Reputation: 1205Reputation: 1205
Quote:
Originally Posted by Firerat View Post
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.
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
 
Old 08-28-2019, 01:28 PM   #18
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 1,992

Rep: Reputation: 549Reputation: 549Reputation: 549Reputation: 549Reputation: 549Reputation: 549
Quote:
Originally Posted by pedropt View Post
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

Last edited by Firerat; 08-28-2019 at 01:31 PM.
 
Old 08-28-2019, 02:26 PM   #19
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 1,992

Rep: Reputation: 549Reputation: 549Reputation: 549Reputation: 549Reputation: 549Reputation: 549
I have just made a quick test in a VM

from tty2
Code:
while true;do df > /dev/tty1;sleep 2;done
so , screen ,tmux or nohup can be used to keep the script alive
edit: or systemd.service, cron@reboot ( if you have that )..

that output is a little ugly ( ok very)
your script need to be modified to output nicly

Code:
watch df > /dev/tty1
looks normal, but if you press a key output is lost ( have to restart the watch )

obvoiusly you need permission to write to tty1

Last edited by Firerat; 08-28-2019 at 02:31 PM.
 
Old 08-29-2019, 09:51 AM   #20
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 217

Original Poster
Rep: Reputation: Disabled
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 .

Last edited by pedropt; 08-29-2019 at 10:18 AM.
 
Old 08-29-2019, 10:23 AM   #21
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 1,992

Rep: Reputation: 549Reputation: 549Reputation: 549Reputation: 549Reputation: 549Reputation: 549
but what does the script you want to run do?

when you echo "stuff" > /dev/tty1
it just prints it on the screen, it is not entering it to the login program

is your intent is to login to run a script which then displays things on the physical screen?

if so than you need to
Code:
./yourscript.sh > /dev/tty1
that will probably look messy, you will need to format the output of your script.
I'm guessing
Code:
printf "%s\n\r" "your msg"
that is just a guess, you will have to play with it, printf is probably better than echo, you will have much more control over the formating

Once you have your script outputting correctly, then nohup,tmux,screen will keep that script alive
if you are using bash4,
Code:
coproc /path/to/script.sh
coproc is a replacement for nohup

hell , you might even get away with
Code:
/path/to/script.sh > /dev/tty1 &
in /etc/rc.local
 
2 members found this post helpful.
Old 08-29-2019, 10:24 AM   #22
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 3,844

Rep: Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320Reputation: 1320
Have you tried openvt? Example:
Code:
openvt --switch -- /bin/bash /path/to/script

Last edited by NevemTeve; 08-29-2019 at 01:54 PM. Reason: Example
 
Old 08-29-2019, 10:50 AM   #23
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 217

Original Poster
Rep: Reputation: Disabled
Thank you firerat , it works perfectly
 
Old 08-29-2019, 11:12 AM   #24
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 1,992

Rep: Reputation: 549Reputation: 549Reputation: 549Reputation: 549Reputation: 549Reputation: 549
np

which solution did you go for?
 
Old 08-29-2019, 01:38 PM   #25
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 217

Original Poster
Rep: Reputation: Disabled
Quote:
/path/to/script.sh > /dev/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 .
 
Old 08-29-2019, 02:43 PM   #26
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.6
Posts: 3,635

Rep: Reputation: 1205Reputation: 1205Reputation: 1205Reputation: 1205Reputation: 1205Reputation: 1205Reputation: 1205Reputation: 1205Reputation: 1205
Quote:
Originally Posted by pedropt View Post
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"
 
Old 08-29-2019, 04:06 PM   #27
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 217

Original Poster
Rep: Reputation: Disabled
thank you Scasey for the input .
 
Old 08-29-2019, 11:55 PM   #28
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,112
Blog Entries: 3

Rep: Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003
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:

Code:
tmux sendtotty2 tmux attach-session -t tty2
tmux attach-session -t tty2
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.
 
Old 08-30-2019, 02:14 AM   #29
pedropt
Member
 
Registered: Aug 2014
Distribution: Devuan
Posts: 217

Original Poster
Rep: Reputation: Disabled
Thanks Turbocapitalist for the info , i will give a test to it to see how it works when i get some free time .
 
Old 08-30-2019, 02:43 AM   #30
Turbocapitalist
Senior Member
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 4,112
Blog Entries: 3

Rep: Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003Reputation: 2003
No worries. I did spot a mistake in the previous post and have edited in the correction.

Also if you would like the console's session to be read only, you can make a slight variation in the above.

Code:
tmux new-session -s tty2 -d
sudo sendtotty2 tmux attach-session -t tty2 -r $'\n'
tmux attach-session -t tty2
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot sequentially press Alt key then menu accelerator, must press both concurrently Woodsman Slackware 1 03-21-2013 03:21 PM
Unable to enter password in terminal to enter as root.. ANISHKUMAR.R Linux - Newbie 5 08-07-2010 07:46 AM
LXer: http://www.clusterresources.com/pages/press/press-releases.php LXer Syndicated Linux News 0 04-12-2006 07:21 AM
Boot Disk Failure, Insert System Disk and Press Enter!! novkhan Linux - Hardware 1 12-15-2005 07:39 PM
"Disk boot failure. Enter system disk and press enter" Fear58 Linux - Hardware 3 06-25-2004 05:17 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:46 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration