mirror of
https://codeberg.org/Windfluechter/cleanup-mastodon-users.sh.git
synced 2025-06-16 00:58:14 +00:00
Instead of deleting right away after the limit has been reached, the users will now be deactivated. The new "--cron" option can now be invoked more often (like hourly, daily, whatever) to delete the deactivated users. You can define how many accounts get deleted in each cron run. Default is 2 users. Reason for this is to prevent too much load on the server when hundreds or even thousands of users get deleted. Also there is some statistics at the end when the script runs.
cleanup-mastodon-users.sh
Script to remove inactive users on your Mastodon server. This is a small cleanup script for Mastodon node admins to help with forgotten or dead accounts.
The script does two things:
- delete all users after 2 weeks that haven't logged in at all and didn't post anything.
- search for accounts that haven't logged in for 6 months, send them a reminder mail and delete accounts that haven't logged within 7 months.
Installation
- save the script in home directory of Mastodon (eg. ~/bin, not under /root, maybe /usr/local/bin)
- make the script executable (e.g.
chown mastodon:mastodon bin/cleanup-mastodon-users.sh && chmod u+rx bin/cleanup-mastodon-users.sh)
- create a crontab to execute the script, e.g.:
20 8 * * 4 /home/mastodon/bin/cleanup-mastodon-users.sh --dowhatimean
to execute the script every week. In the example it is executed every Thursday (4th day of week) at 8:20 in the morning. - for the first runs you should set
UPPERLIMIT
to a high number and keep the deleting of the user commented out (${mastodonpath}/bin/tootctl accounts delete "${username}"
). After the first few runs you can reduceUPPERLIMIT
to a lower setting and repeat this until you reached the final value. You shouldn't have too many weeks betweenLOWERLIMIT
andUPPERLIMIT
. Sensible values might be 6 and 7 months or 12 and 13 months or so. - change the variables at the begin of the script to your site settings.
Usage
Usage:
--dry-run : make a dry-run, no deletion will be done, no mails are sent.
--dowhatimean : add this option if you really want to delete users.
Other useful tips
- test the script by using
--dry-run
argument with the script - you can change the mail command from
-b ${siteadmin} -- ${usermail}
to-- ${siteadmin}
and comment out all lines withbin/console user delete
statement for testing runs
Donations
If you want to support my work, you can donate via LiberaPay:
or on Patreon
Languages
Shell
100%