How do I show an alert in virtual console ttyX (not necessarily the active one) so that the user sees the alert on the next command invocation. I'm looking for something similar to the "you have mail" alert.
If you know which user is logged in on which virtual console, you can use
write. E.g., assume user
dirk is logged in on
tty2, you can do
echo 'You have a message' | write dirk tty2
and the user will see the message (with two additional lines). The user on the virtual console needs to enable receiving messages with
mesg y, unless you send the message as root IIRC. The user sees this message immediately, no matter if he invokes a command or not.
The alternative would be to hook into the shell of the user (possible using the
PS prompts) by setting up
.profile etc. to actively check for messages in some file etc.