Premium
BASH Snippets.

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

BASH

Deploy Website Files via Rsync over SSH

A robust Bash script to securely deploy website files to a remote server using rsync over SSH, ensuring only changed files are transferred efficiently.

View Snippet →
BASH

Bash Script to Manage Nginx Service

Create a flexible Bash script to easily start, stop, restart, reload configurations, or check the status of your Nginx web server service using systemctl.

View Snippet →
BASH

Generate Cryptographically Secure Random Passwords

Learn to generate strong, random, and cryptographically secure passwords or strings directly from your Bash terminal using system entropy sources.

View Snippet →
BASH

Automate Web Server Reload on Configuration File Changes

Automatically monitor web server configuration files (Nginx or Apache) for changes and gracefully reload the service to apply updates without downtime.

View Snippet →
BASH

Sync Local Changes to Remote Server with rsync

Perform incremental file synchronization from a local development environment to a remote server using rsync for efficient and fast deployments.

View Snippet →
BASH

Backup PostgreSQL/MySQL Database and Compress

Automate daily or weekly backups of your PostgreSQL or MySQL database, compressing the dump file for efficient storage and easy recovery.

View Snippet →
BASH

Check if a Specific Network Port is Already in Use

Verify if a particular TCP port is currently open and actively listening on the system, preventing conflicts when starting new services.

View Snippet →
BASH

Create a Secure SSH Tunnel for Local Port Forwarding

Establish a secure SSH tunnel to forward a remote port to a local port, enabling access to services on a remote network as if they were local.

View Snippet →
BASH

Monitor Disk Usage and Alert on High Consumption

Regularly check disk space usage on specified partitions and send an email alert if consumption exceeds a predefined threshold.

View Snippet →
BASH

Automate Web App Deployment with Git and NPM

A bash script to automate web application deployment, including pulling the latest code from Git, installing Node.js dependencies, and restarting a PM2 or systemd service.

View Snippet →
BASH

Monitor Apache/Nginx Logs for Specific Errors

A bash script to continuously tail and filter web server access or error logs (Apache/Nginx) for specific keywords like "ERROR", "500", or "denied", providing real-time monitoring.

View Snippet →
BASH

Check if a Network Port is Open and Service is Responsive

A bash script to check if a specific network port on a given host is open and optionally, if a basic HTTP/S service is responsive, useful for server health checks.

View Snippet →