Linux: One time message on login

centoslinux

I am looking for a command similar to wall but will deliver a message to users currently sshed in and if they are not logged in will display upon their next ssh login( but only once ). Context is that I may( not guaranteed ) have a network outage but not everyone on the machine(s) will have gotten the maintenance email and I would rather forward the email to all the users of the machine(s). Not looking to put a message in /etc/motd since that will put up the message upon every login.

Best Answer

There's a standard way of doing this: news. In olden times this was a standard command, but these days it's a bit crusty and has to be installed manually. The Debian/Ubuntu package you want is sysnews.

To use it,

  • create a file called something like /var/lib/sysnews/login-message containing your message
  • add news to /etc/profile (or equivalent for your users' shell)

When your users log in, they'll see the message the first time, but then .news_time is created in their home directory, and they'll only see news items that have been modified since the timestamp of that file.