Skip to content

RedjiJB/linux-automation-suite

Repository files navigation

Linux Automation Suite

License: MIT Bash Platform ShellCheck

A comprehensive, enterprise-grade collection of Bash scripts designed to automate critical system administration tasks on Linux-based systems. This suite provides unified solutions for automated backups, intelligent log analysis, and cron job management.


Table of Contents


Features

Automated Backup System

  • Full and incremental backups with GNU tar's snapshot feature
  • Multiple compression algorithms: gzip, bzip2, xz (configurable levels)
  • Optional GPG encryption for sensitive data
  • Integrity verification with SHA256/MD5 checksums
  • Retention policies with automatic cleanup
  • Remote synchronization via rsync or scp

Intelligent Log Analysis

  • Pattern-based detection with 50+ predefined security patterns
  • Multi-source monitoring: syslog, auth.log, application logs
  • Severity classification: INFO, WARNING, ERROR, CRITICAL
  • Real-time monitoring mode for continuous surveillance
  • HTML report generation with visual dashboards
  • Security-focused analysis for threat detection

Cron Job Management

  • Centralized job registry with metadata tracking
  • Job validation before installation
  • Enable/disable jobs without manual crontab editing
  • Execution history and performance logging
  • Automatic crontab backup before modifications
  • Interactive job creation

Notification System

  • Email alerts via SMTP with TLS support
  • Configurable thresholds for alert triggering
  • Multiple notification levels: success, warning, error, critical

Quick Start

# Clone the repository
git clone https://github.com/RedjiJB/linux-automation-suite.git
cd linux-automation-suite

# Run a backup status check
./bin/backup.sh status

# List configured cron jobs
./bin/cron_manager.sh list

# Perform a log analysis
./bin/log_analyzer.sh --quick

Installation

Prerequisites

  • Operating System: Linux (Ubuntu 20.04+, Debian 11+, RHEL 8+, CentOS Stream 8+)
  • Bash: Version 4.2 or higher
  • Required packages: tar, gzip, rsync, cron

Option 1: Quick Install (Development)

Use the suite directly from the cloned repository:

git clone https://github.com/RedjiJB/linux-automation-suite.git
cd linux-automation-suite
chmod +x bin/*.sh install.sh

Option 2: System-Wide Installation

Install to /opt/linux-automation-suite with symlinks:

# Check prerequisites
./install.sh --check

# Install system-wide (requires root)
sudo ./install.sh

# Verify installation
backup --help

Option 3: Custom Installation

# Install to custom directory
sudo ./install.sh --dir /usr/local/automation-suite

# Install without symlinks
sudo ./install.sh --no-symlinks

# Install with custom ownership
sudo ./install.sh --user admin --group admin

Post-Installation

# Edit configuration
sudo nano /opt/linux-automation-suite/etc/automation.conf

# Install cron jobs
sudo /opt/linux-automation-suite/bin/cron_manager.sh install

# Verify cron jobs
crontab -l

Usage

Backup Operations

# Perform a full backup
./bin/backup.sh full

# Perform an incremental backup
./bin/backup.sh incremental

# Full backup with custom options
./bin/backup.sh full -c xz -e    # xz compression + encryption

# Show backup status
./bin/backup.sh status

# List all backups
./bin/backup.sh list

# Verify backup integrity
./bin/backup.sh verify

# Clean up old backups
./bin/backup.sh cleanup

# Dry run (show what would be done)
./bin/backup.sh full --dry-run

Log Analysis

# Quick analysis (last 15 minutes)
./bin/log_analyzer.sh --quick

# Hourly analysis with metrics
./bin/log_analyzer.sh --hourly

# Generate daily summary report
./bin/log_analyzer.sh --summary

# Security-focused analysis
./bin/log_analyzer.sh --security

# Real-time monitoring (continuous)
./bin/log_analyzer.sh --realtime

# Analyze specific log files
./bin/log_analyzer.sh -f "/var/log/apache2/error.log"

# Custom alert threshold
./bin/log_analyzer.sh --threshold 5

Cron Job Management

# List all registered jobs
./bin/cron_manager.sh list

# Install enabled jobs to crontab
./bin/cron_manager.sh install

# Enable a specific job
./bin/cron_manager.sh enable backup_daily

# Disable a job
./bin/cron_manager.sh disable backup_weekly

# Run a job immediately
./bin/cron_manager.sh run backup_daily

# Show job status
./bin/cron_manager.sh status backup_daily

# View execution history
./bin/cron_manager.sh history

# Validate job registry syntax
./bin/cron_manager.sh validate

# Add a new job interactively
./bin/cron_manager.sh add

# Backup current crontab
./bin/cron_manager.sh backup

# Restore crontab from backup
./bin/cron_manager.sh restore crontab_backup_20260203.txt

Configuration

Main Configuration File

Edit etc/automation.conf to customize the suite:

# Global Settings
ADMIN_EMAIL="admin@example.com"
LOG_LEVEL="INFO"                    # DEBUG, INFO, WARNING, ERROR, CRITICAL

# Backup Configuration
BACKUP_SOURCE="/home /etc /var/www"
BACKUP_COMPRESSION="gzip"           # gzip, bzip2, xz, none
BACKUP_RETENTION_DAYS="30"
BACKUP_ENABLE_ENCRYPTION="false"

# Log Analysis Configuration
LOG_FILES="/var/log/syslog /var/log/auth.log"
LOG_ALERT_THRESHOLD="10"

# Notification Settings
NOTIFY_ENABLED="true"
NOTIFY_ON_SUCCESS="true"
NOTIFY_ON_ERROR="true"

Log Patterns

Define custom patterns in etc/log_patterns.conf:

# Format: PATTERN_NAME|REGEX|SEVERITY|ACTION
FAILED_LOGIN|Failed password for|WARNING|count
SERVICE_FAILED|Failed to start|ERROR|alert
CUSTOM_ERROR|MyApp.*ERROR|ERROR|alert

Cron Jobs

Register jobs in etc/cron_jobs.conf:

# Format: JOB_ID|SCHEDULE|COMMAND|DESCRIPTION|ENABLED
backup_daily|0 2 * * *|${AUTOMATION_HOME}/bin/backup.sh incremental|Daily backup|true
my_custom_job|0 */6 * * *|/path/to/script.sh|My custom job|true

Directory Structure

linux-automation-suite/
├── bin/                        # Executable scripts
│   ├── backup.sh               # Backup automation
│   ├── log_analyzer.sh         # Log analysis
│   └── cron_manager.sh         # Cron job management
├── etc/                        # Configuration files
│   ├── automation.conf         # Main configuration
│   ├── log_patterns.conf       # Log pattern definitions
│   └── cron_jobs.conf          # Cron job registry
├── lib/                        # Shared libraries
│   ├── common.sh               # Common utilities
│   ├── logger.sh               # Logging functions
│   └── notify.sh               # Notification functions
├── logs/                       # Log output directories
│   ├── backup/                 # Backup operation logs
│   ├── log_analysis/           # Analysis reports
│   └── cron/                   # Cron execution logs
├── backups/                    # Backup storage
│   ├── full/                   # Full backup archives
│   └── incremental/            # Incremental backups
├── docs/                       # Documentation
│   └── IMPLEMENTATION.md       # Implementation guide
├── install.sh                  # Installation script
├── README.md                   # This file
└── LICENSE                     # MIT License

Requirements

Minimum Requirements

Component Version Notes
Bash 4.2+ Required for associative arrays
tar Any Backup archiving
gzip Any Default compression
cron Any Job scheduling

Recommended Packages

# Ubuntu/Debian
sudo apt install tar gzip bzip2 xz-utils rsync gnupg mailutils cron

# RHEL/CentOS
sudo dnf install tar gzip bzip2 xz rsync gnupg2 mailx cronie

Optional Dependencies

Package Purpose
gpg Backup encryption
rsync Remote synchronization
mailutils Email notifications
bzip2 Alternative compression
xz-utils High-ratio compression

Documentation

Document Description
README.md Quick start and usage guide
IMPLEMENTATION.md Complete implementation guide
Technical Documentation Detailed specifications

Security Considerations

  • Configuration files contain sensitive settings—restrict permissions to 600
  • Backup directories should be owned by root with 700 permissions
  • Use GPG encryption for backups containing sensitive data
  • Store encryption keys in a secure key management system
  • Regularly audit cron jobs and execution logs
  • Use SSH key-based authentication for remote synchronization
# Secure configuration files
sudo chmod 600 /opt/linux-automation-suite/etc/*.conf
sudo chown root:root /opt/linux-automation-suite/etc/*.conf

# Secure backup directory
sudo chmod 700 /opt/linux-automation-suite/backups

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Run ShellCheck validation (shellcheck bin/*.sh lib/*.sh)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Code Style

  • Follow Google Shell Style Guide
  • All scripts must pass ShellCheck validation
  • Use meaningful variable names with UPPER_CASE for constants
  • Include function documentation comments
  • Test on multiple Linux distributions

License

This project is licensed under the MIT License - see the LICENSE file for details.


Author

Redji Jean Baptiste
Computer Systems Technician - Networking
Algonquin College



Built for system administrators everywhere

About

Bash scripts for automated backups, log analysis, and cron job management

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages