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.
-
3What is the problem with getting this message multiple times upon login? Just remove it after the outage is done or definitely not necessary.– SvenMar 14, 2013 at 12:30
-
1It's annoying to get spammed with countless messages when it's always the same thing, I guess that's the only reason.– gparentMar 14, 2013 at 16:03
-
That is pretty much the reason, I know I open up two or three shell sessions and quite a number of users login on somewhat spotty internet connections so getting hit with the same message a couple dozen times a day gets irritating quickly.– VincentAlphaMar 14, 2013 at 17:41
2 Answers
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.
-
Sounds like exactly what I am looking for, just need to find a package for CentOS then. Cheers! Mar 14, 2013 at 17:44
-
@VincentAlpha did you find the package for CentOS? I looked for a while but was unable to. Posting it here could help other future users. Jul 2, 2018 at 14:47
-
@user3243242 Unfortunately not, and it seems back then I didn't even find the source (or consider building it from source); just checked a rocks server I sysadmin and no luck in the 7.0 repos either (the one for the question was CentOS 5 or 6). Jul 3, 2018 at 15:49
-
@VincentAlpha thank you for checking! For anyone stumbling across this qusetion, I ended up implementing themel's solution. Jul 3, 2018 at 19:44
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
-
Dont you mean if [ ! -e "$HOME/.saw-the-message" ]; ?– user160910Mar 14, 2013 at 13:01