Premium
BASH Snippets.

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

BASH

Automating File and Directory Backups

Create a simple Bash script to automate daily backups of specified files or directories, compressing them and adding a timestamp for easy recovery.

View Snippet →
BASH

Monitoring and Restarting a Process Automatically

Implement a Bash script to continuously monitor a specific process (e.g., a web server or background worker) and automatically restart it if it's found to be down.

View Snippet →
BASH

Parsing Script Arguments with Getopts

Learn how to parse command-line options and arguments in Bash scripts using `getopts`, enabling flexible and user-friendly script execution with various parameters.

View Snippet →
BASH

Automating Remote File Deployment with SCP

Deploy files and directories to a remote web server securely using `scp` within a Bash script, streamlining your deployment workflow for web applications.

View Snippet →
BASH

Implementing Basic Log File Rotation

Manage growing log files by implementing a simple Bash script for rotation, compression, and deletion of old logs, preventing disk space exhaustion on servers.

View Snippet →
BASH

Securely Deploy Static Website via Rsync with Configuration

Automate the deployment of a static website to a remote server using rsync, including secure SSH key authentication and configurable paths for web developers.

View Snippet →
BASH

Check and Wait for a TCP Port to Become Available

Create a robust Bash script to repeatedly check if a specific TCP port on a host is open, useful for ensuring service dependencies are ready in CI/CD pipelines.

View Snippet →
BASH

Parse Command-Line Arguments with Getopts for Flexible Bash Scripts

Learn to parse short command-line options and their arguments in Bash using `getopts`, enabling more powerful and user-friendly script interactions for developers.

View Snippet →
BASH

Graceful Service Restart with PID File and Health Check

Implement a robust Bash script to gracefully stop, start, and restart a service using a PID file, including a basic HTTP health check for reliability in deployments.

View Snippet →
BASH

Efficiently Find Large Files in a Directory and Subdirectories

Locate and list the largest files within a specified directory, including subdirectories, sorted by size, useful for disk space management and web asset optimization.

View Snippet →
BASH

Load Environment Variables from .env File

A Bash script to source and export variables from a .env file, making environment-specific configurations accessible in your shell or for specific commands.

View Snippet →
BASH

Check Website Uptime and HTTP Status

A robust Bash script to perform a health check on a given URL, reporting its HTTP status code and response time, essential for monitoring web services.

View Snippet →