I've found this question, but it talks about a version of Ubuntu with a GUI. I'm referring to Ubuntu Server, so no GUI. I've also found this question, but it doesn't look like it will display the output of a command, but instead only static text.
The Ubuntu Server login screen looks something like this:
Ubuntu 22.04 LTS mycomputer tty1
mycomputer login:
However, I'd like it to run a command (either as root or under my account - you can pick), and then I'd like it to print the output of the command before giving the login prompt.
For example, if my command was echo Hello world!, I'd like it to look like this:
Hello world!
Ubuntu 22.04 LTS mycomputer tty1
mycomputer login:
Or this would be fine too:
Ubuntu 22.04 LTS mycomputer tty1
Hello world!
mycomputer login:
While it was in my example, the output of my command can change - it isn't gaurenteed to be the same each time, so I can't hardcode the output of the command into a file (in my case, the command is hostname -i, which prints the IP address).
I often need to check the IP of a machine, and it would be easier if I didn't have to sign in to check it. For the sake of the question, assume this is a personal server on a home network, and so leaking the IP address isn't a concern.
How can I display the output of a command in the command-line login screen?
