Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.