4

I've been tinkering with my CentOS server login procedure, I want to have my MOTD update using the linux_logo program. I've already tried doing this in a few ways, but didn't get the desired effect. I have started with this command:

/usr/bin/linux_logo -c -u -y -t "$R" > /etc/motd

The key info to be updated here is the uptime.

I have tried adding it to my .bashrc file, and adding the command to a new bash script in /etc/profile.d/ folder, and making it executable. Both of these methods make it run at login, but only after the MOTD has been printed, so it's one login behind.

I also created an init script with the command in it using chkconfig to set it to start at runtime levels 345, this I believe just made it run the script during boot.

I have also tried adding the following to my sshd_config file:

ForceCommand /usr/bin/linux_logo -c -u -y -t "$R" > /etc/motd

This had the effect of closing my ssh connection every time I logged in :/

These were all suggestions from similar posts I found when googling for this, so I think I am missing something, at this point some help would be appreciated.

To summarise, I want the following, or similar command to run at login, prior to the motd being printed. Is this possible?

if [ -f /usr/bin/linux_logo ]; then
  /usr/bin/linux_logo -c -u -y -t "$R" > /etc/motd
fi
4
  • 1
    Why not just run it in a crontab every hour or so?
    – terdon
    Oct 21, 2014 at 18:58
  • I suppose I could, I just thought this was a designed function of linux_logo, since it has a flag for showing the uptime of the server, why is it so difficult to use?
    – Rumbles
    Oct 21, 2014 at 19:21
  • I don't see anything hard about adding a crontab. Do you know how to? It would be trivial to just run that command every few minutes and update your motd.
    – terdon
    Oct 21, 2014 at 19:35
  • yeah I guess that's the sensible way to do it, I just thought it made more sense for it to be triggered at logon I guess just adding it to crontab -e
    – Rumbles
    Oct 21, 2014 at 19:38

3 Answers 3

4

According to the wikipedia article the /etc/motd is called before it executes the login shell. That explains why including anything in the .bashrc file doesn't work.

Via chkconfig and links in /etc/rcX.d/ the update is indeed only done at startup.

One thing you could try and look into is replace /etc/motd with a named pipe ( mkfifo /etc/motd ) and have a program somehow detect the reading from that pipe and fill the pipe with the desired output.

3

There is no reason to have this run when a user logs on, just add it to root's crontab or /etc/crontab. To run your command and update the motd every 5 minutes, add this line to /etc/crontab:

*/5 * * * * root /usr/bin/linux_logo -c -u -y -t "$R" > /etc/motd
6
  • Yes, there are reasons to have things run when the user logs on. This does not answer the question. Aug 15, 2023 at 12:33
  • @GrahamLeggett it answers this question, as you can see the OP accepted this answer. If you need something else, you can ask a new question, explaining what you need and why it needs to be run when the user logs on. Of course there are valid reasons to run things when a user logs on, but updating motd, which is what this question was about, isn't one of them, that's all.
    – terdon
    Aug 15, 2023 at 12:37
  • The question is "Updating MOTD on login", this answer is for the question "Updating MOTD prior to login", which is a different question. Aug 23, 2023 at 10:50
  • @GrahamLeggett I disagree, this is answering what the user really needed instead of what they asked and that is a very common thing here: we always try to answer the real question and not the XY problem. But no worries, if you still disagree, downvote. That's how the sites work.
    – terdon
    Aug 23, 2023 at 10:53
  • I'm here to find the answer to the question "Updating MOTD on login", which is the question at the top of this post. If you answer a different question, you make life more difficult for everyone else. If you want to answer a different question, open a new post with the correct question at the top. Aug 25, 2023 at 16:35
1

in modern linux, anything that will write to /etc/motd.dynamic will change login.

If you want to do it 'right', create /etc/update-motd.d and place scripts there whose output will compose the MOTD.

See

https://ownyourbits.com/2017/04/05/customize-your-motd-login-message-in-debian-and-ubuntu/

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .