Author Topic: Clear alerts & notifications from CLI?  (Read 83 times)

0 Members and 1 Guest are viewing this topic.

Offline
*****
Clear alerts & notifications from CLI?
« on: December 07, 2025, 10:56:31 PM »
Anyone know how to clear the Alerts & Notifications completely out from the CLI?

There is a scripts to add alerts, but didn't see any for read and/or clear.


Thanks

Offline
*****
Re: Clear alerts & notifications from CLI?
« Reply #1 on: December 08, 2025, 11:56:05 AM »
I poked around one day but didn't come up with any solid answers.

Online
**
Re: Clear alerts & notifications from CLI?
« Reply #2 on: December 10, 2025, 10:17:21 AM »
The below is the json file you'd need to alter to be an empty array, it houses the notifications. It can't be empty though, must always contain an empty array eg: [] - or the GUI will crash. There are JSON terminal tools like js & sponge etc that can edit the file if your brave. Alernatively you can execute a python script to overwrite the file contents with empty array

/usr/local/cwpsrv/htdocs/resources/admin/include/libs/notifications/notifications.json

« Last Edit: December 10, 2025, 10:41:04 AM by 6Sense »
Web Design, Development & Web Hosting
https://6sense.com.au

Online
**
Re: Clear alerts & notifications from CLI?
« Reply #3 on: December 11, 2025, 04:02:52 AM »
A python solution is to create the below file called clear_notices.py in /usr/local/cwpsrv/htdocs/resources/admin/include/libs/notifications (when executed it simply replaces the notification data which is stored in an array with an empty array)

Code: [Select]
import json
filename = 'notifications.json'
clear_notifications = []

try:
    with open(filename, 'w') as json_file:
        json.dump(clear_notifications, json_file, indent=4)
    print(f"Successfully edited '{filename}' to be an empty array [].")
except FileNotFoundError:
    print(f"Error: The file '{filename}' was not found.")
except Exception as e:
    print(f"An error occurred: {e}")

You can then run in via the terminal

Code: [Select]
cd /usr/local/cwpsrv/htdocs/resources/admin/include/libs/notifications
python3 clear_notices.py

You can also set up up cron job to run it as often as you wish
Web Design, Development & Web Hosting
https://6sense.com.au

Offline
*****
Re: Clear alerts & notifications from CLI?
« Reply #4 on: December 11, 2025, 04:30:35 AM »
Bravo! But if I'm not missing something, wouldn't it be easiest to empty the notifications like so:
Code: [Select]
echo '[]' > /usr/local/cwpsrv/htdocs/resources/admin/include/libs/notifications/notifications.json

Online
**
Re: Clear alerts & notifications from CLI?
« Reply #5 on: December 11, 2025, 04:57:00 AM »
Yup, works too!
Web Design, Development & Web Hosting
https://6sense.com.au