A New Day
🤖 System Automation & Documentation#
1. Bash Scripting: Log Cleaner#
This script checks the system log, archives old files, and removes everything older than 30 days. Perfect for keeping your server clean.
#!/bin/bash
LOG_DIR="/var/log/myapp"
ARCHIVE_DIR="/var/log/myapp/archive"
# Create archive directory if it doesn't exist
mkdir -p "$ARCHIVE_DIR"
echo "Starting log maintenance..."
# Move logs older than 7 days to archive
find "$LOG_DIR" -name "*.log" -mtime +7 -exec mv {} "$ARCHIVE_DIR" \;
# Delete archived logs older than 30 days
find "$ARCHIVE_DIR" -name "*.log" -mtime +30 -delete
echo "Maintenance complete: $(date)"
2. Installation Procedure#
Follow these steps to deploy the script locally:
- Step 1: Create the file:
touch cleanup.sh - Step 2: Grant execution permissions:
chmod +x cleanup.sh - Step 3: Add to Crontab for automation:
0 0 * * * /path/to/cleanup.sh
3. Environment Variables#
| Variable | Description | Default Value |
|---|---|---|
LOG_DIR | Where the application writes logs | /var/log/myapp |
MAX_AGE | Days before deletion | 30 |
4. Technical Note#
Note: Keep in mind that the
find -deleteoperation is irreversible. Always test with
Summary of Syntax Used:#
- Bash Code Block: Uses triple backticks with
bashfor syntax highlighting. - Bullet Points: Simple overview of progress steps.
- Tables: For parameter definitions.
- Blockquotes: For important warnings.
Read other posts