1

I have a mostly headless server running Debian with no xorg/graphical environment installed. At boot it simply shows a text-mode login prompt.

I am wondering how could I show the output of a command before any users have logged in (in the login screen of my terminal)? The command would display just like with the watch command, updating every 2 seconds or so and need not be interactive.

NOTE: I am aware that in most scenarios, simply running an SSH session to the machine and run a watch would be sufficient, or installing a web-server that could provide what I need in a browser would be much better. However both those are for different reasons not practical in my scenario. Also as a pure quenching of my curiosity I would like to know how the answer to this question.

1

Off the top of my head, you could do something like:

  1. Write a script to do whatever you need (maybe just watch somecommand, maybe more complex)
  2. Create a user account, and set that script to its login shell
  3. Adjust your getty to auto-login that user

This might break the ability to log in normally; it would take some experimenting to figure that out.

The normal mechanism for showing login-time information, of course, is /etc/issue. However, looking at that, it doesn't seem suitable, due to 1. no mechanism to run arbitrary commands and output those, 2. no mechanism to update output continually, rather than print once.

  • Actually I will try that. My guess is that once the command exits, it will log out, so in the case of watch it would simply mean ctrl+c or q to exit. As long as there are other users then circumventing this should work fine – Lennart Rolland Nov 20 '15 at 23:01
  • The problem is that when you log out, it'll drop you back in getty, which will autologin again as that user. I don't know how to make getty's behavior conditional. – Tom Hunt Nov 20 '15 at 23:01
0

As noted, /etc/issue is shown in the right place, but is a static message.

You could script /etc/issue by forcing the getty processes to restart occasionally, though a 2-second interval would interfere with logon. A more practical interval would be about a minute.

With Debian, you are probably using agetty (see manual page). It can be restarted by sending a SIGHUP to it (as root, of course, since getty runs as root).

For related reading:

0

instead of running login immediately at tty initialization, run a script like the following instead:

#!/bin/sh
(   trap '' TTOU
    while   clear
    do      #gen your output
            sleep 2
    done
) & stty -icanon
    dd    count=1 >/dev/null 2>&1
    stty  icanon
    exec  login

...that will run whatever you put in your loop until at least a single byte is read from the tty, at which time login will be called up. login always starts off with a HUP on its controlling tty, and so the backgrounded process writing your output to the terminal will die as soon as it does, but until someone presses a key it will continue to cycle over producing whatever output you wish. Even if it can write output to its controlling tty from the background, no matter what your backgrounded loop tries to do, though, it will never succeed in reading any input from it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.