Manage and display system news using a simple but effective utility.
Software installation
Install sysnews
utility.
$ sudo apt-get install sysnews
Basic information
System news uses plain text files located in /var/lib/sysnews
directory. This directory belongs to the user root
and group staff
and has an SGID bit set.
File modification time is used as the message date.
The application uses modification time of ~/.news_time
to distinguish between old and new system news. It updates this file on every run.
Create system news
Create system news as the root user
As root
user you can simply create a new file.
$ echo "Hello, this is an initial message" | sudo tee /var/lib/sysnews/initial_message
Create system news as a regular user
The user needs to belong to the staff
group.
$ sudo usermod -a -G staff milosz
Create system news in /var/lib/sysnews/
directory.
milosz$ echo "Hello, this is a message from milosz" | tee /var/lib/sysnews/milosz_initial_message
User can create, edit, remove its own system news as SGID bit is set on a directory.
$ stat /var/lib/sysnews File: /var/lib/sysnews Size: 4096 Blocks: 8 IO Block: 4096 directory Device: 801h/2049d Inode: 136046 Links: 2 Access: (2775/drwxrwsr-x) Uid: ( 0/ root) Gid: ( 50/ staff) Access: 2019-09-03 21:39:34.246965900 +0000 Modify: 2019-09-03 21:39:04.658852430 +0000 Change: 2019-09-03 21:39:04.658852430 +0000 Birth: -
$ ls -l /var/lib/sysnews/ total 8 -rw-r--r-- 1 root staff 34 Sep 3 21:28 initial_message -rw-r--r-- 1 milosz staff 37 Sep 3 21:39 milosz_initial_message
User notification
Create /etc/profile.d/news.sh
shell script that will display system news.
#!/bin/bash echo "System news" echo "-----------" news
Ensure that the executable bit is set.
$ sudo chmod +x /etc/profile.d/news.sh
Verify that it works as expected.
$ sudo su - milosz System news ----------- ** initial_message (root) Tue Sep 3 21:28:23 2019 Hello, this is an initial message ** milosz_initial_message (milosz) Tue Sep 3 21:39:05 2019 Hello, this is a message from milosz
The application will update the ~/.news_time
file, so it will mark any older system news as already read.
$ ls -l ~/.news_time -rw------- 1 milosz milosz 0 Sep 3 21:51 /home/milosz/.news_time
Purge old system news
By default, the application will use cron
to delete anything older than 30
days, except WELCOME
, POLICY
and NEWUSERS
files.
$ cat /etc/cron.daily/sysnews #!/bin/sh -e # CRON script to purge files in /var/lib/sysnews after 30 days. # Exclude files named WELCOME/POLICY/NEWUSERS, since they are intended to # stay for new users. The files POLICY/NEWUSERS are not supplied by the # Debian package because they are site-specific. if [ -x /usr/bin/news ]; then news -e 30 -x WELCOME,POLICY,NEWUSERS fi
You can create /var/lib/systemnews/.noexpire
file to extend the list of excluded files using a comma-separated list and/or newlines.
$ echo -e "initial_message,message\nmilosz_initial_message" | sudo tee /var/lib/sysnews/.noexpire initial_message,message milosz_initial_message
Additional options
Display the number of system news.
$ news --articles --all NEWS: 2 news articles
Display the number of unread system news.
$ news --articles NEWS: 1 news article
Display the names of system news.
$ news --all --names NEWS: initial_message milosz_initial_message
Display names of unread system news.
$ news --names NEWS: milosz_initial_message
Display system news.
$ news --all ** initial_message (root) Tue Sep 3 21:57:40 2019 Hello, this is an initial message ** milosz_initial_message (milosz) Tue Sep 3 21:59:42 2019 Hello, this is a message from milosz
Display unread system news.
$ news ** milosz_initial_message (milosz) Tue Sep 3 22:08:27 2019 Hello, this is a message from milosz