0

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?

3 Answers3

1

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.

Stephen Kitt
  • 434,908
1

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.

RudiC
  • 8,969