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
  • 1
    Why not just run it in a crontab every hour or so? – terdon Oct 21 '14 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 '14 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 '14 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 '14 at 19:38
4

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
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.

-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/

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.