Premium
BASH Snippets.

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

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 →
BASH

Extract Data from JSON Files using jq

A bash script demonstrating how to parse and extract specific data from JSON files or API responses using the powerful `jq` command-line JSON processor.

View Snippet →
BASH

Delete Old Files and Directories by Age

Automatically clean up stale log files, temporary build artifacts, or cached data by deleting files and empty directories older than a specified number of days to free up space.

View Snippet →
BASH

Monitor and Restart a Background Process

Ensure critical background services (like Node.js apps or queue workers) stay running by checking their status and automatically restarting them if they're down.

View Snippet →
BASH

Automate Frontend Build and Sync

Streamline your web development workflow by automating the 'npm install' and 'npm run build' steps for frontend projects, then synchronizing the build output to a target directory.

View Snippet →
BASH

Recursive Text Find and Replace

Efficiently update text strings across multiple files and directories in your project. Ideal for refactoring variable names, updating URLs, or changing configuration values recursively.

View Snippet →