Linux: One time message on login
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.
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.
Do you have a global /etc/profile
that you could do this from? Won't catch everyone and their weird shell of the day, but basically
if [ ! -e "$HOME/.saw-the-message" ];
echo "The system will go down tomorrow, but I will never tell you again!"
touch $HOME/.saw-the-message
fi
Problems:
- you'll have to clean up the lock files afterwards
- misses some people who use
$weird_shell