I am planning on write CLI program. This CLI program should have ability to run at scheduled time.
Is it possible for this program to somehow notify user's shell? Sort of like mail
tells you that you have unread mail?
I am planning on write CLI program. This CLI program should have ability to run at scheduled time.
Is it possible for this program to somehow notify user's shell? Sort of like mail
tells you that you have unread mail?
If I understood your question, to send a GUI notification you could use:
notify-send
xmessage
zenity
For more info
Mail checks are implemented in various shells. Presumably you don’t want to get an additional check added to the shells your users are likely to use. To get a similar check, the simplest approach is to implement a tool which produces the appropriate output when a notification should be displayed, and run that from your users’ shell startup scripts.
There are various examples of this; if you check your system’s /etc/profile.d
, you might find similar tools you can use as inspiration. For example, on systems with abrt
(RHEL etc.), you’ll find an abrt-console-notification.sh
script which displays abrt
’s status when users log in.
Try a write user
from within your cron job. Like putting a
x y z * * write user%message%
into your crontab
.
But be aware: that user must be logged in to be notified. A simple terminal session under GUI will not.
If using (a recent) bash
or similar shell, setting PROMPT_COMMAND
using an arbitrary file like
PROMPT_COMMAND='[ -f /tmp/msg ] && cat /tmp/msg && rm /tmp/msg'
and having a crontab
entry like
x y z * * echo message > /tmp/msg
will display "message" once right before the next prompt.
cron
. Add a line incrontab
for when to start the shellscript. You can find good tutorials about cron and crontab via the internet. The shellscript can write 'anywhere' according to where you tell it to write. You may need some special fix to allow writing to some places. – sudodus May 30 '22 at 15:50mail
program does it – user3056783 May 30 '22 at 16:54