Is it possible to write a shell script that enables any user (may not be root) to set a message(e.g. "Download on progress do not turn off" etc.) which will be conveyed like pop-up message (zenity or notify-send) to all other users. If any user is not there at the time of throwing the message they must get it on login or unlocking their screen.
Nice question. Will give just an half answer... just a seed to see if someone can prepare something starting on this. I have tested this in my system, two users (ubuntu and romano, the two administrators).
I go to a VC and log in as ubuntu --- then I run
(the first sudo switch to superuser, the second sudo execute
zenity
as the userromano
)from a virtual console, the message will appear in "romano" graphical environment.
I suppose that with a bit of mangling the output of
w
to get the DISPLAY and the users and looping over them it would be possible to have a working solution. Non-graphical connected users can be informed usingwall
.I see really difficult to do that without superuser privileges, tough.
If you don't find a direct solution, problems like this can be solved by creating a (simple, in this case) daemon program that runs with elevated privileges and runs when the system starts.
Then, a regular user user can put a file somewhere the daemon will see it or send the daemon a message and the daemon can then do whatever action required elevated privileges.
You just have to be careful what input the daemon accepts so you don't open any security holes in your system.
There is an almost unlimited variety of things that can happen when you pass an unedited character string to a bash script running with elevated privileges! For that reason alone, it would be much better if your daemon were written in a language such as Python where you can do whatever you want to an incoming string before the system gets any chance to interpret/execute its contents.
For users logging in, you can probably add a few lines to /etc/profile which tell the daemon to issue any messages the user needs to see. If you do that, you should probably also do something to avoid unnecessary repetitions when the user logs in again. That's more work, but will keep alerts from turning into nagware.
I think what I did is really a bad way to do things. Anyway it works upto a certain level. Any suggestion to improve the script or a better script is always welcome. I tried to do this with the help of the answers given by Rmano and Joe.
I have created a file at
/home/message.txt
which has permission-rw-rw-rw-
so that any user (may not member ofsudo
gropu) can write their message in it. I have written two scripts both having permissions-rwxr-xr-x
/usr/bin/msg_on_login.sh
to pass the message to the users on their login/usr/bin/msgpass.sh
to pass the message to the users who are on their system (screen may be locked)msg_on_login.sh
and add this line "
/usr/bin/msg_on_login.sh
" at the end of/etc/profile
and change permission of /usr/bin/msg_on_login.sh to-rwxr-xr-x
. Then the script will run each time any user login and he will get the message.msgpass.sh
change permission of
/usr/bin/msgpass.sh
to-rwxr-xr-x
.Cons
msgpass.sh
stumbles over and gives error.msgpass.sh
you need to have member of sudo group.Note