Premium
BASH Snippets.

Curated list of production-ready BASH scripts and coding solutions.

BASH

Parse Command Line Options with `getopts`

A robust bash script demonstrating how to parse command-line arguments and options using `getopts` for flexible script execution.

View Snippet →
BASH

HTTP Service Health Check Script

A bash script to perform a basic HTTP health check on a web service, useful for monitoring, deployment validation, and automated checks.

View Snippet →
BASH

Automate Log File Cleanup by Age

Learn to create a bash script for automatically cleaning up old log files from a specified directory, preventing disk space exhaustion and maintaining server health.

View Snippet →
BASH

Simple Website Backup Using rsync

Implement a robust bash script to create incremental backups of website files using rsync, ensuring data integrity and efficient storage for disaster recovery.

View Snippet →
BASH

Extract Top IP Addresses from Access Logs

Learn to parse Apache or Nginx access logs using bash, awk, and sort to identify and count the most frequent IP addresses accessing your web server.

View Snippet →
BASH

Update All Git Repositories in a Directory

Automate updating multiple Git repositories within a specified parent directory using a bash script, streamlining development workflows for microservices or multi-project setups.

View Snippet →
BASH

Load Environment Variables from .env File in Bash

Learn how to load environment variables from a .env file into your Bash script for dynamic configuration, commonly used in web development projects.

View Snippet →
BASH

Validate Presence of Essential CLI Tools in Bash

Ensure your Bash scripts have all necessary command-line tools installed (e.g., node, npm, git) before execution, providing robust error handling.

View Snippet →
BASH

Create Timestamped Directory Backup with Tar

Safely backup your web project directories by creating a timestamped gzipped tar archive, ensuring you have a restore point before major changes.

View Snippet →
BASH

Robust HTTP Server Health Check with Retries

Implement a Bash script to health-check a web server's HTTP status with retry attempts, crucial for deployment verification and CI/CD pipelines.

View Snippet →
BASH

Automate NVM Setup and Node Version Switching

Streamline your Node.js development workflow by automating NVM (Node Version Manager) initialization and switching between Node versions in Bash scripts.

View Snippet →
BASH

Automate Web Server Restart with Status Check

Learn to write a robust bash script for restarting Nginx or Apache, including pre-check for configuration syntax and post-check for service status.

View Snippet →