
sudo nano /usr/local/bin/message_server.sh
#!/bin/bash
# message_server.sh - Clean version without lock screen pollution
SERVER_IP="0.0.0.0"
PORT=9999
LOG_FILE="/var/log/teacher_messages.log"
# Create log file if it doesn't exist
touch "$LOG_FILE"
chmod 644 "$LOG_FILE"
# Log function that only writes to file (not stdout)
log_message() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOG_FILE"
}
# Initial log entry (only to file, not screen)
log_message "Teacher Message Server starting on port $PORT"
# Suppress all status messages from terminal output
while true; do
# Run netcat quietly and process messages
nc -l -p $PORT -w 3600 2>/dev/null | while read -r line; do
if [ -n "$line" ]; then
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
LOG_ENTRY="[$TIMESTAMP] $line"
# Log to file only
echo "$LOG_ENTRY" >> "$LOG_FILE"
# Show desktop notification (this will queue until screen unlocks)
notify-send -t 10000 -u critical "💬 Teacher Message" "$line"
# Optional: Play sound notification
if command -v paplay &> /dev/null && [ -f "/usr/share/sounds/freedesktop/stereo/message.ogg" ]; then
paplay /usr/share/sounds/freedesktop/stereo/message.ogg &
fi
fi
done
# If netcat exits, wait briefly and restart (quietly)
sleep 2
done