slackcat
Send command output to Slack
TLDR
Post a file to Slack
Post a file to Slack with a custom filename
Pipe command output to Slack as a text snippet
Stream command output to Slack continuously
SYNOPSIS
slackcat [options] [file...]
command | slackcat [options]
PARAMETERS
--token
Slack API token (e.g., xoxb-YOUR_BOT_TOKEN or xoxp-YOUR_USER_TOKEN).
--channel
Target channel or user (e.g., #general, @user, or channel ID C12345).
--filename
Filename displayed in Slack (defaults to stdin or actual filename).
--title
Title for the Slack message/file.
--filetype
File type for syntax highlighting (e.g., text, auto, bash, json, log).
--unfurl
Enable link unfurling (if supported by token type).
--raw
Upload content as a raw file without pretty printing.
--pretty
Format content for pretty printing (e.g., using jq for JSON).
--webhook
Use a Slack Incoming Webhook URL instead of a token.
--username
Override the bot's username (for webhooks).
--icon-emoji
Override the bot's icon with an emoji (for webhooks).
--icon-url
Override the bot's icon with an image URL (for webhooks).
--initial-comment
Add an initial comment to the file upload.
-v, --version
Print version information and exit.
-h, --help
Display help message and exit.
DESCRIPTION
slackcat is a command-line utility that enables users to pipe standard input (e.g., output from other commands) or send local files directly to a Slack channel or user. It acts like the cat command but instead of printing to standard output, it uploads the content to Slack. It's particularly useful for integrating shell scripts with Slack, sending alerts, logs, or quick reports without leaving the terminal.
slackcat supports various options to customize the message, including specifying the target channel, the filename displayed in Slack, the file type for syntax highlighting, and whether to unfurl links. It can authenticate using a Slack API token (legacy or bot) or a Slack Incoming Webhook URL.
CAVEATS
API Token Security: Directly embedding API tokens in scripts can be a security risk. Consider using environment variables (e.g., SLACKCAT_TOKEN) or a secure vault.
Webhook vs. Token: Webhooks offer less control (e.g., no file uploads, only messages) but are simpler. API tokens provide more features but require proper scope management.
Rate Limiting: Frequent or large uploads might hit Slack API rate limits, leading to errors or temporary blocks.
File Size Limits: Slack has file size limits (currently 1GB per file for uploads, but very large files might be slow to process).
Network Dependency: Requires an active internet connection to communicate with Slack.
ENVIRONMENT VARIABLES
slackcat often supports reading SLACKCAT_TOKEN and SLACKCAT_CHANNEL environment variables, removing the need to specify them with command-line flags for every invocation. This is a recommended practice for managing sensitive information like API tokens.
PIPING AND FILE ARGUMENTS
slackcat can receive input either by piping data to its standard input (e.g., ls -l | slackcat) or by specifying file paths as arguments (e.g., slackcat mylog.txt otherlog.log). When both are provided, it typically processes the piped input first, then the files.
HISTORY
slackcat was developed as a simple, Unix-friendly tool to bridge the gap between command-line operations and Slack notifications. Its creation aimed to provide a lightweight alternative to more complex integrations or directly using curl with Slack APIs, making it easy for developers and system administrators to send data to Slack channels directly from their shell scripts or interactive sessions. It gained popularity for its straightforward usage pattern, mirroring the beloved cat command, but with a network destination. It's often found in various open-source repositories, with ongoing development adapting to Slack API changes.