# Please eval short Ruby script to suspend inactive users

**URL:** https://meta.discourse.org/t/please-eval-short-ruby-script-to-suspend-inactive-users/324795
**Category:** Development
**Created:** [September 3, 2024, 11:00pm UTC](https://meta.discourse.org/t/please-eval-short-ruby-script-to-suspend-inactive-users/324795 "2024-09-03T23:00:42Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![TonyG](https://avatars.discourse-cdn.com/v4/letter/t/f14d63/32.png) [@TonyG](https://meta.discourse.org/u/TonyG)
#### Post date: [September 3, 2024, 11:21pm UTC](https://meta.discourse.org/t/please-eval-short-ruby-script-to-suspend-inactive-users/324795/2 "2024-09-03T23:21:08Z")

</div>

Hmm, as I look at that I think I should be silencing an account rather than suspending. If the account is suspended, the user can’t login to claim the account.

Here is a revision …

> **Version 0.0.2**
>
> ```plaintext
> silence_reason = 'Inactive'
> User.where("views = 0 OR approved = FALSE OR last_seen_at IS NULL")
> .where("id > 0") # avoid system users
> .find_each do |user|
> user.silence(reason: silence_reason)
> user.change_trust_level!(TrustLevel[0])
> user.save!
> logger.log_user_silence(user, silence_reason)
> DiscourseEvent.trigger(:user_silenced, user: user)
> sleep(5)
> end
> 
> ```

Yes, I will run a backup before doing any of this.  
Yes, I know some existing TLs will get shuffled around and I’ll need to fix them.

In addition, to or rather than silencing, should I set Approved=false or Active=false? I believe that will force the user to click the email link rather than manually doing a login, which serves the purpose of validating the email address.

This is all related to my recent thread: [notes-on-silencing-or-deleting-users](https://meta.discourse.org/t/notes-on-silencing-or-deleting-users)

[EDIT]  
I also have “purge unactivated users grace period days” set to 7.  
Does a silence or suspend reset this? If so, if peeps don’t respond to an account action within 7 days, I have no problem with purging them.

Finally (yes, really) I also have “clean up inactive users after days” set to 365. I can set that down to 60 while the forum is still opening up and just let existing accounts fall off the list. Then increase it back to 365. Is that a reasonable approach for automated account pruning on a new environment?

---

_[View the full topic](https://meta.discourse.org/t/please-eval-short-ruby-script-to-suspend-inactive-users/324795)._
