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:
- Set up a Notifery account and created at least one zone (see Getting Started)
- Generated an API key for your zone
- Basic familiarity with Bash scripting
Setting Up the Script
-
Download the notifery-event.sh script to your server or local machine
-
Make the script executable:
Terminal window chmod +x notifery-event.sh -
Edit the script to include your API key:
Terminal window # Open the script in a text editorvim notifery-event.sh# Replace the DEFAULT_API_KEY value with your API keyDEFAULT_API_KEY="your-api-key-here"
Basic Usage
The basic syntax for using the script is:
./notifery-event.sh "Title" zone#group "command to execute"
Where:
Title
: The title for your notificationzone#group
: Your zone alias, optionally followed by a group aliascommand to execute
: The command or script you want to monitor
Example
./notifery-event.sh "Daily Backup" backups#database "/usr/bin/mysqldump -u root mydb > /backups/mydb.sql"
This will:
- Execute the mysqldump command
- Capture its output and exit code
- Send a notification to the “backups” zone, “database” group with the title “Daily Backup”
- 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:
# Run a backup script every day at 2 AM and monitor it with Notifery0 2 * * * /path/to/notifery-event.sh "Daily Backup" server#backups "/path/to/backup-script.sh" > /dev/null 2>&1
Example
# Backup MongoDB database every day at 3 AM0 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:
# Open the script in your editorvim notifery-event.sh
# Uncomment and modify the ZONE_API_KEYS sectionZONE_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:
./notifery-event.sh "System Update" server "/usr/bin/apt update && /usr/bin/apt upgrade -y"
Troubleshooting
If you’re not receiving notifications:
- Verify your API key is correct
- Check that the zone and group names match exactly with what’s configured in Notifery
- Ensure the script has execute permissions
- Check network connectivity to the Notifery API