Make sure you have bash and flock (from util-linux package) installed –– they are in all Linux distros by default ––, create /var/log/eventlog.user with appropriate rw access to the group of users that are allowed to use this, and save the following as a script those users can execute:
#!/bin/bash
# EVENTFILE: path to the event file
export EVENTFILE=/var/log/eventlog.user
# EVENTS: number of events to show; default 20, overridable
EVENTS=$(($EVENTS-0))
[[ $EVENTS -le 0 ]] && EVENTS=20
while [[ 1 ]]; do
clear
printf 'Events up to %s:\n' "$(date '+%Y-%m-%d %H:%M:%S %z')" >&2
flock -s "$EVENTFILE" tail -n $EVENTS "$EVENTFILE"
printf 'Enter to refresh, CTRL+D to exit, or text for new entry:\n' >&2
printf '> ' >&2
read Line || break
# Remove leading and trailing whitespace
Line="${Line//[[:space:]]/ }"
Line="${Line# }"
Line="${Line% }"
if [[ -n "$Line" ]]; then
export MSG="$(date '+%Y-%m-%d %H:%M:%S %z') $(id -un): ${Line}"
flock -e "$EVENTFILE" -c 'echo "$MSG" >> "$EVENTFILE"'
fi
done
printf '[Ctrl-D]\n' >&2
It works absolutely fine even if multiple users use it at the same time, because it uses flock to advisory-log the event log file during reading and appending. The downside is that new entries are not automatically shown, the user must press Enter to see any new messages.
If you were to put the display of the log and appending to the log into separate shell scripts (/usr/share/eventlog/list and /usr/share/eventlog/add for example, controlled by environment variables EVENTFILE and EVENTS), it would be very easy to have them color-code the output, too, if so desired (and if the connection is to a tty: if $(stty &>/dev/null); then is-a-tty; else not-a-tty; fi).
Personally, however, I'd write a small C program for this, using ncursesw, so that it'd work like a real-time chat, except using the file for the chat record.
Lemme know if that would be useful; other members here could perhaps suggest useful notation (like auto-highlighting patterns like [space]@[username]).[/code]