Skip to content

Instantly share code, notes, and snippets.

@voice1
Created December 6, 2018 18:44
Show Gist options
  • Save voice1/a868b997c89ffccb2cbaf79092707eec to your computer and use it in GitHub Desktop.
Save voice1/a868b997c89ffccb2cbaf79092707eec to your computer and use it in GitHub Desktop.
slack-cleaner wrapper to automate slack message clean up.
#!/bin/bash
#
# Automated cleanup of slack messages.
# Must have slack-cleaner already installed.
# Simply replace your SLACK_TOKEN string with your legacy webapi token.
# Set the number of days you wish to retain, and add this to a cron job to run at
# the desired interval.
SLACK_TOKEN=My-Slack-Legacy-WebToken
DAYS=-30
BEFORE=$(date -v${DAYS}d +%Y%m%d)
echo "Cleaning up channels"
slack-cleaner --rate 1 --token $SLACK_TOKEN --message --channel ".*" --regex --bot --before $BEFORE --perform
slack-cleaner --rate 1 --token $SLACK_TOKEN --message --channel ".*" --regex --user "*" --before $BEFORE --perform
slack-cleaner --rate 1 --token $SLACK_TOKEN --file --channel ".*" --regex --before $BEFORE --perform
echo "Cleaning up Direct Messages (DM's)"
slack-cleaner --rate 1 --token $SLACK_TOKEN --message --direct ".*" --regex --bot --before $BEFORE --perform
slack-cleaner --rate 1 --token $SLACK_TOKEN --message --direct ".*" --regex --user "*" --before $BEFORE --perform
slack-cleaner --rate 1 --token $SLACK_TOKEN --file --direct ".*" --regex --before $BEFORE --perform
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment