Skip to content

Command Monitoring

Monitor the execution of any command, script, or cronjob and receive instant notifications about their status with the notifery-event.sh utility script.

Overview

The notifery-event.sh script is a powerful utility that allows you to:

  • Wrap any command or script to monitor its execution
  • Capture output and exit codes
  • Send notifications when commands complete or fail
  • Organize notifications into zones and groups

Prerequisites

Before using the notifery-event.sh script, make sure you have:

  1. Set up a Notifery account and created at least one zone (see Getting Started)
  2. Generated an API key for your zone
  3. Basic familiarity with Bash scripting

Setting Up the Script

  1. Download the notifery-event.sh script to your server or local machine

  2. Make the script executable:

    Terminal window
    chmod +x notifery-event.sh
  3. Edit the script to include your API key:

    Terminal window
    # Open the script in a text editor
    vim notifery-event.sh
    # Replace the DEFAULT_API_KEY value with your API key
    DEFAULT_API_KEY="your-api-key-here"

Basic Usage

The basic syntax for using the script is:

Terminal window
./notifery-event.sh "Title" zone#group "command to execute"

Where:

  • Title: The title for your notification
  • zone#group: Your zone alias, optionally followed by a group alias
  • command to execute: The command or script you want to monitor

Example

Terminal window
./notifery-event.sh "Daily Backup" backups#database "/usr/bin/mysqldump -u root mydb > /backups/mydb.sql"

This will:

  1. Execute the mysqldump command
  2. Capture its output and exit code
  3. Send a notification to the “backups” zone, “database” group with the title “Daily Backup”
  4. Include the command output and status in the notification

Using with Cron Jobs

The notifery-event.sh script is particularly useful for monitoring cron jobs. Here’s how to integrate it with your crontab:

Terminal window
# Run a backup script every day at 2 AM and monitor it with Notifery
0 2 * * * /path/to/notifery-event.sh "Daily Backup" server#backups "/path/to/backup-script.sh" > /dev/null 2>&1

Example

Terminal window
# Backup MongoDB database every day at 3 AM
0 3 * * * /home/user/notifery-event.sh "Backup MongoDB" production#backups "/bin/bash /home/user/backup-mongodb.sh"

Advanced Configuration

Zone-Specific API Keys

You can configure different API keys for different zones by editing the script:

Terminal window
# Open the script in your editor
vim notifery-event.sh
# Uncomment and modify the ZONE_API_KEYS section
ZONE_API_KEYS["zone-alias-production"]="production-api-key-here"
ZONE_API_KEYS["zone-alias-staging"]="staging-api-key-here"

This allows you to use different API keys based on the zone specified in the command.

Monitoring Without Groups

If you want to monitor a command without specifying a group, simply omit the group part:

Terminal window
./notifery-event.sh "System Update" server "/usr/bin/apt update && /usr/bin/apt upgrade -y"

Troubleshooting

If you’re not receiving notifications:

  1. Verify your API key is correct
  2. Check that the zone and group names match exactly with what’s configured in Notifery
  3. Ensure the script has execute permissions
  4. Check network connectivity to the Notifery API