Created
February 24, 2024 13:58
-
-
Save lgrn/36dcf095494c9135676eee95d93ebc00 to your computer and use it in GitHub Desktop.
disable any mastodon users not active for the past 7890000 seconds (91.3 days)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
DB_HOST=1.2.3.4 | |
DB_PORT=5432 | |
DB_NAME=mastodon_production | |
DB_USER=mastodon | |
PGPASSWORD=yourpassword psql -h ${DB_HOST} -p ${DB_PORT} -d ${DB_NAME} -U ${DB_USER} -w -1 -t -A -F" " -c "SELECT accounts.username, TRUNC(EXTRACT(EPOCH FROM (NOW() - current_sign_in_at))) AS diff FROM users JOIN accounts ON users.account_id = accounts.id WHERE (approved = TRUE AND disabled = FALSE)" | while read -r user time; | |
do | |
if [[ -v user && time -ge 7890000 ]]; then | |
RAILS_ENV='production' /home/mastodon/live/bin/tootctl accounts modify $user --disable | |
echo "$user SUSPENDED for exceeding 7 890 000 seconds" | |
else | |
echo "$user is OK!" | |
fi | |
done |
@SISheogorath good idea, almost certainly scales a lot better. In our case the size of the instance is minimal though.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I don't think you have to bother with the time comparison in the shell script, let the DB do the heavy lifting: