New in CWP Edge-LatestFree with every CWPpro licenceWebsites up to 300x faster

CWP now includes LSPHP, LSAPI-Cache and CWP Cage at no extra cost with all CWPpro licences. The LSAPI-Cache plugin is integrated into our WordPress and other script installers, and CWP Cage gives every user complete isolation. Available now in the CWP Edge-Latest version.

Get CWPpro ›

Clear alerts & notifications from CLI?

Started by Starburst, December 07, 2025, 10:56:31 PM

Previous topic - Next topic

Starburst

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

overseer

I poked around one day but didn't come up with any solid answers.

6Sense

#2
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

6Sense - Web Design, Development & Web Hosting

6Sense

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)

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

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
6Sense - Web Design, Development & Web Hosting

overseer

Bravo! But if I'm not missing something, wouldn't it be easiest to empty the notifications like so:
echo '[]' > /usr/local/cwpsrv/htdocs/resources/admin/include/libs/notifications/notifications.json

6Sense

6Sense - Web Design, Development & Web Hosting

Starburst

And here, CWP actual said it could not be done...  ???

Starburst

Quote from: overseer 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:
echo '[]' > /usr/local/cwpsrv/htdocs/resources/admin/include/libs/notifications/notifications.json

@overseer I like it, simple and quick.

cyberspace

Quote from: overseer 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:
echo '[]' > /usr/local/cwpsrv/htdocs/resources/admin/include/libs/notifications/notifications.json

Excellent ! Simple and effective solution  :)