Premium
BASH Snippets.

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

BASH

Deploy Website Files with Rsync

Efficiently deploy your website's updated files to a remote server using rsync over SSH, ensuring only changed files are transferred for faster deployments.

View Snippet →
BASH

Monitor Web Service Health with HTTP Status

Create a bash script to periodically check the HTTP status code of a web service endpoint and report if it's down or returning error codes (e.g., 4xx, 5xx).

View Snippet →
BASH

Parse API JSON Responses with JQ

Use a bash script with `jq` to extract, filter, and transform specific data from JSON API responses, enabling efficient command-line data processing and automation.

View Snippet →
BASH

Auto-Cleanup Old Log Files

Implement a bash script to automatically delete log files older than a specified number of days, freeing up valuable disk space on your web server and preventing log bloat.

View Snippet →
BASH

Parse Command Line Arguments in Bash

Learn to parse command-line arguments using `getopts` in Bash, enabling flexible and configurable script execution for various web development automation tasks and utilities.

View Snippet →
BASH

Batch Rename Files with a Pattern

Efficiently rename multiple files based on a pattern using a Bash script, useful for organizing assets or cleaning up project directories in web development workflows.

View Snippet →
BASH

Gracefully Restart a Web Service

Implement a Bash script to gracefully restart a web service (e.g., Nginx, Apache, or a Node.js process) using systemd, ensuring minimal downtime and proper resource management during deployments.

View Snippet →
BASH

Automate PostgreSQL Database Backups with Retention

Learn to automate PostgreSQL database backups using bash, incorporating timestamps for versioning and implementing a retention policy to manage old backups efficiently.

View Snippet →
BASH

Securely Deploy Website Files with Rsync and SSH

Master using rsync over SSH for efficient and secure deployment of website files, including excluding specific directories and verbose output for debugging.

View Snippet →
BASH

Monitor Server Disk Space and Send Email Alerts

Implement a bash script to monitor server disk space usage, automatically sending an email alert when a predefined threshold is exceeded, preventing potential outages.

View Snippet →
BASH

Parse Command Line Arguments in Bash with getopts

Discover how to robustly parse command-line options and arguments in bash scripts using `getopts`, supporting both short and long options for flexible script execution.

View Snippet →
BASH

Interact with REST APIs using cURL and Parse JSON with jq

Learn to make authenticated GET and POST requests to REST APIs using `curl` and effectively parse the JSON responses with `jq` in your bash scripts for automation.

View Snippet →