Premium
BASH Snippets.

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

BASH

Configure HTTP Strict Transport Security (HSTS) in Nginx

Enhance web security by configuring HSTS in Nginx, forcing browsers to communicate with your server exclusively over HTTPS and preventing downgrade attacks.

View Snippet →
BASH

Create and Navigate to New Project Directory

Automate the creation of a new project directory structure and immediately navigate into it, streamlining development setup for web projects.

View Snippet →
BASH

Real-time Log File Monitoring for Keywords

Monitor a specified log file continuously for the occurrence of specific keywords, useful for real-time debugging and error detection in web server logs.

View Snippet →
BASH

Automate Timestamped Directory Backup

Create a compressed, timestamped archive of a specified directory, ideal for regular backups of web project files, databases, or configurations.

View Snippet →
BASH

Monitor and Restart a System Service

Automatically check if a specified systemd service is active and restart it if it's not, ensuring continuous availability for web applications or databases.

View Snippet →
BASH

Deploy Static Web Content with Rsync

Efficiently deploy static website files from a local directory to a remote server using rsync, ensuring only changed files are transferred for faster updates.

View Snippet →
BASH

Load Project Environment Variables from .env File

Safely load environment variables from a .env file into the current shell session, crucial for local development and CI/CD pipelines in web projects.

View Snippet →
BASH

Perform HTTP Request and Inspect Response with cURL

Use cURL within a Bash script to make HTTP GET requests, displaying full response headers and the body, essential for debugging web services and APIs.

View Snippet →
BASH

Enforce Git Commit Message Format with a Hook

Implement a `commit-msg` Git hook in Bash to validate commit messages against a regex pattern, ensuring consistent, readable, and structured commit history.

View Snippet →
BASH

Verify Required Command Line Tools Availability

A Bash script to check for the presence of essential command-line tools like `node` or `docker`, notifying users if any are missing to ensure proper development environment setup.

View Snippet →
BASH

Simple Web Service Control Script

Create a basic Bash script to manage a web service, providing convenient start, stop, and status functionalities using `nohup` for background execution.

View Snippet →
BASH

Automate Full Website Backups (Files & DB)

Create a robust bash script to automate daily backups of your web application's files and MySQL/PostgreSQL database, storing them with timestamps for recovery.

View Snippet →