DEV Community

Sundance
Sundance

Posted on

Automating Software Development & System Administration: How Shell Scripts Can Save You Hours of Work

Save more time with automated scriptsAs developers and system administrators, we often find ourselves performing the same tasks repeatedly. Whether it's managing Git branches, checking system health, backing up databases, or deploying applications, these routine operations consume valuable time that could be better spent solving more complex problems.

The Power of Automation

After years of writing ad-hoc scripts to solve individual problems, I decided to organize and enhance my collection of automation tools. The result is auto_scripts - a comprehensive library of shell scripts designed to streamline common tasks across system administration, development workflows, DevOps practices, and database management.

What's Inside the Repository

The collection is organized into four main categories, each addressing different aspects of the development and operations lifecycle:

System Administration

These scripts handle everything from basic system monitoring to advanced health checks with adaptive thresholds:

  • VM detection - Identifies if your environment is virtualized using multiple detection methods.
  • System health monitoring - Tracks CPU, memory, disk usage, and load averages with dynamic alerting thresholds.
  • Disk usage alerts - Notifies when partitions exceed configurable thresholds.
  • Update utilities - Simplifies package management with colorized output.

One particularly useful script, syshealth.sh, demonstrates how monitoring can be made smarter:

# Calculate dynamic thresholds based on historical averages
if [[ -f "${HISTORY_DIR}/cpu.log" ]]; then
    CPU_AVG=$(awk '{ total += $1; count++ } END { print total/count }' "${HISTORY_DIR}/cpu.log")
    CPU_THRESHOLD=$(echo "$CPU_AVG * $THRESHOLD_MULTIPLIER" | bc)
else
    CPU_THRESHOLD=80
fi

# Save current metrics for future threshold calculations
echo "$CPU_USAGE" >> "${HISTORY_DIR}/cpu.log"

# Alert if thresholds exceeded
if (( $(echo "$CPU_USAGE > $CPU_THRESHOLD" | bc -l) )); then
    echo "ALERT: CPU usage ($CPU_USAGE%) exceeds dynamic threshold of $CPU_THRESHOLD%" |
    mail -s "System Alert: High CPU Usage" "$ALERT_RECIPIENT"
fi
Enter fullscreen mode Exit fullscreen mode

Development Workflows

For developers, Git management can consume significant time. The repository includes tools that simplify common Git operations:

  • Git Branch Manager - A comprehensive interactive tool for creating, deleting, and merging branches.
  • Auto Git - Streamlines the commit and push workflow.
  • Python Environment Setup - Automatically creates and configures virtual environments.

The git_branch_management.sh script transforms complex Git operations into simple menu selections:

# Display main menu
show_main_menu() {
  clear
  echo -e "${BLUE}========================================${NC}"
  echo -e "${YELLOW}        GIT BRANCH MANAGER${NC}"
  echo -e "${BLUE}========================================${NC}"
  echo ""
  echo -e "${GREEN}1${NC}. Create a new branch"
  echo -e "${GREEN}2${NC}. Delete a branch"
  echo -e "${GREEN}3${NC}. Merge branches"
  echo -e "${GREEN}4${NC}. List all branches"
  echo -e "${GREEN}0${NC}. Exit"
}
Enter fullscreen mode Exit fullscreen mode

DevOps and Deployment

Continuous integration and deployment become more manageable with:

  • CI/CD Automation - Handles integration, testing, code quality checks, and deployment.
  • Deployment Script - Deploys applications from Git repositories to target servers.
  • Backup Utilities - Simple but effective file backup with timestamping.

Database Management

Database administrators will appreciate tools for:

  • Advanced Database Maintenance - Performs backups, optimization, monitors connections, and generates reports.
  • Database Backup - Simple MySQL backup utility with error checking and timestamping.

Why This Collection Matters

  1. Production-Ready: Error handling, parameter validation, and confirmation prompts make these scripts robust enough for real-world use.
  2. Educational Value: Clear comments explain what each section does, making them excellent learning resources.
  3. Customizability: Every script is designed to be easily modified for your specific environment.
  4. Time-Saving: Automating routine tasks can save hours each week.

Real-World Example: Automated Git Management

Managing Git branches properly is critical but time-consuming. The git_branch_management.sh script simplifies operations like:

  • Creating feature branches from the correct base branch.
  • Safely deleting branches with checks for unmerged changes.
  • Managing remote branches.
  • Handling merge operations with conflict detection.

What might take multiple commands with careful checking becomes a single menu-driven operation, reducing errors and ensuring consistency.

Getting Started

  1. Clone the repository: git clone https://github.com/sundanc/auto_scripts.git
  2. Make scripts executable: chmod +x script_name.sh
  3. Run the script: ./script_name.sh

Some scripts may require root privileges or specific configurations—always check the comments at the top of each file.

Contribute and Customize

The repository is designed to be extended. Contributions are welcome:

  • Add clear comments to explain your code.
  • Include error handling where appropriate.
  • Use consistent formatting.
  • Document any dependencies or prerequisites.

Conclusion

Automation isn't just about saving time—it's about consistency, reliability, and freeing your mental bandwidth for more important tasks. Whether you're an experienced system administrator, a DevOps engineer, or a developer looking to streamline your workflow, these scripts provide a solid foundation you can build upon.

Check out the auto_scripts repository on GitHub, star it if you find it useful, and feel free to adapt these tools to your specific needs.

Because in the end, the best code is the code you don't have to write repeatedly.


Have you created automation scripts that saved you hours of work? Share your experiences in the comments below!

Top comments (0)