A collection of bash scripts for system administration, monitoring, backup, and media management.
This repository contains various utility scripts designed for DietPi/Linux system administration. All scripts have been reviewed, debugged, and standardized for better reliability and consistency.
backup-OS.sh- Creates compressed system backups excluding temporary directoriesserver_health_check.sh- Comprehensive system health monitoring with Telegram notificationsmonitor_containers.sh- Docker container health monitoring and automatic restartonedrive-check.sh- OneDrive service monitoring and restart functionalitytrack_processes.sh- Process monitoring and logging to CSV format
optimized_docker_backup_to_onedrive.sh- Optimized Docker volume backup with OneDrive synccommon_functions.sh- Shared utility functions for logging, Telegram notifications, and system checks
build_spotify_titles_full.sh- Extract track titles from Spotify playlists via APIspotdl_chunked.sh- Download Spotify playlists using spotdl in chunksspotdl_linewise.sh- Line-by-line parallel Spotify track downloadingspotdl_sync.sh- Spotify playlist synchronization scriptytdlp_linewise.sh- YouTube track downloading with parallel processingytdlp_smart_match.sh- Smart matching YouTube downloads with fuzzy search
telegram_notify.sh- Standalone Telegram notification sender
- Environment Variables: Create
/root/.envwith required credentials:
# Telegram Bot Configuration
BOT_TOKEN=your_telegram_bot_token
CHAT_ID=your_telegram_chat_id
# Spotify API (for Spotify scripts)
SPOTIPY_CLIENT_ID=your_spotify_client_id
SPOTIPY_CLIENT_SECRET=your_spotify_client_secret
SPOTIPY_REDIRECT_URI=http://localhost:8765/callback
# Optional backup settings
BACKUP_RETENTION_DAYS=5
ZSTD_LEVEL=3
CPU_THRESHOLD=85
RAM_THRESHOLD=90
DISK_THRESHOLD=90- Required System Packages:
# Essential packages
apt update
apt install -y curl jq tar zstd bc
# For media scripts
pip install spotdl yt-dlp
# For monitoring (optional)
apt install -y vnstat sensors-utils- Directory Structure:
mkdir -p /mnt/nas/music/lists
mkdir -p /srv/OneDrive/PCBOX-Backup
mkdir -p /var/log/system_stats- Clone or download the scripts:
git clone <repository_url> /root/scripts
cd /root/scripts
chmod +x *.sh- Set up environment file:
cp .env.example /root/.env
# Edit /root/.env with your credentials- Test the common functions:
source common_functions.sh
load_env /root/.env
# Test telegram notification
send_telegram "Test message from $(hostname)"# Run health check
./server_health_check.sh
# Monitor containers
./monitor_containers.sh
# Create system backup
./backup-OS.sh# Build Spotify playlist titles
./build_spotify_titles_full.sh
# Download with spotdl (chunked approach)
./spotdl_chunked.sh
# Download with yt-dlp (line-wise)
./ytdlp_linewise.sh --jobs 4 --list /path/to/titles.txt# Docker backup to OneDrive
./optimized_docker_backup_to_onedrive.sh
# Check OneDrive service
./onedrive-check.sh- ✅ Removed hard-coded credentials
- ✅ Proper environment variable validation
- ✅ Command injection prevention with quoted variables
- ✅ Portable file size detection across different Unix systems
- ✅ Command availability checks before usage
- ✅ Infinite loop prevention in API pagination
- ✅ Consistent error handling and logging
- ✅ Unified environment file loading (
/root/.env) - ✅ Consistent Telegram notification functions
- ✅ Standardized logging patterns
- ✅ Proper script headers with
set -euo pipefail
# System health check every 30 minutes
*/30 * * * * /root/scripts/server_health_check.sh >/dev/null 2>&1
# Container monitoring every 5 minutes
*/5 * * * * /root/scripts/monitor_containers.sh >/dev/null 2>&1
# Daily OS backup at 2 AM
0 2 * * * /root/scripts/backup-OS.sh >/dev/null 2>&1
# OneDrive check every hour
0 * * * * /root/scripts/onedrive-check.sh >/dev/null 2>&1
# Process tracking every minute
* * * * * /root/scripts/track_processes.sh >/dev/null 2>&1# /etc/systemd/system/container-monitor.service
[Unit]
Description=Docker Container Monitor
After=docker.service
[Service]
Type=oneshot
ExecStart=/root/scripts/monitor_containers.sh
User=root
# /etc/systemd/system/container-monitor.timer
[Unit]
Description=Run container monitor every 5 minutes
Requires=container-monitor.service
[Timer]
OnCalendar=*:0/5
Persistent=true
[Install]
WantedBy=timers.target- System scripts:
/var/log/ - Media scripts:
/root/or user-specified - Health monitoring:
/var/log/system_stats/
All scripts implement automatic log rotation when files exceed configured size limits (default: 10MB).
-
Telegram notifications not working
- Verify BOT_TOKEN and CHAT_ID in
/root/.env - Test with:
./telegram_notify.sh "Test message"
- Verify BOT_TOKEN and CHAT_ID in
-
Permission errors
- Ensure scripts are executable:
chmod +x *.sh - Run as root for system-level operations
- Ensure scripts are executable:
-
Missing dependencies
- Check script requirements with command availability checks
- Install missing packages as needed
-
API rate limits
- Spotify/YouTube scripts include rate limiting delays
- Adjust THREADS/JOBS parameters if needed
When modifying scripts:
- Maintain
set -euo pipefailfor strict error handling - Use consistent logging via
common_functions.sh - Quote all variables to prevent word splitting
- Add command availability checks for external tools
- Test thoroughly before deployment
These scripts are provided as-is for system administration purposes. Use at your own risk and ensure you have proper backups before running system-level operations.