Trigger a Webhook After Unrar Extraction

While the standard unrar command-line utility does not have a native feature to send HTTP requests or fire webhooks, you can easily trigger a webhook upon successful extraction by pairing unrar with a simple wrapper script or automation tool. This article explains how extraction exit codes work, demonstrates how to send an instant webhook using a lightweight Bash script, and outlines automated workflows for continuous monitoring.

Why Unrar Cannot Send Webhooks Natively

The official unrar binary is designed solely for archive manipulation and decompression. It does not include an embedded HTTP client or network communication library. Because it focuses strictly on local file operations, it cannot make external network calls on its own.

The Solution: Using Exit Codes and Shell Scripts

Command-line utilities return an exit code upon termination. For unrar, an exit code of 0 signifies a successful extraction with no errors. By checking this code immediately after running the command, you can trigger an HTTP request using tools like curl or wget.

Here is a straightforward Bash script demonstrating this workflow:

#!/usr/bin/env bash

ARCHIVE_PATH="$1"
TARGET_DIR="$2"
WEBHOOK_URL="https://your-domain.com/api/webhook"

# Execute the extraction
unrar x -y "$ARCHIVE_PATH" "$TARGET_DIR"

# Check if unrar completed successfully
if [ $? -eq 0 ]; then
    echo "Extraction successful. Sending webhook..."
    curl -X POST "$WEBHOOK_URL" \
         -H "Content-Type: application/json" \
         -d "{\"status\": \"success\", \"archive\": \"$ARCHIVE_PATH\"}"
else
    echo "Extraction failed. Webhook not sent."
    exit 1
fi

Chaining with the && Operator

For quick manual tasks or one-line operations, you do not need a full script. You can use the shell && operator, which only executes the second command if the first command exits with a status of 0:

unrar x archive.rar /destination/path/ && curl -X POST -H "Content-Type: application/json" -d '{"event":"unrar_completed"}' https://your-domain.com/api/webhook

Automating the Process

If you need this to happen automatically without manual intervention, you can implement one of several approaches:

  • Directory Watchers: Use a Linux daemon like inotifywait or cross-platform utilities like fswatch to monitor a folder for new .rar files, automatically execute unrar, and post to the webhook upon completion.
  • Download Client Post-Processing: Popular tools such as SABnzbd, NZBGet, and qBittorrent support custom post-processing scripts. You can pass the downloaded archive to a script that unpacks it and notifies your endpoint.
  • Docker or Event-Driven Workflows: Containerized microservices or orchestrators like Node-RED can listen for new archive events, run extraction tasks inside a container, and publish status updates to a webhook or message broker.