Premium
BASH Snippets.

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

BASH

Parse and Extract Data from Log Files using Regex

Utilize a bash script to parse log files, extracting specific data patterns like IP addresses, timestamps, or error codes using regular expressions with `grep` and `awk`.

View Snippet →
BASH

Monitor Web Server Error Logs in Real-time

A bash script to continuously monitor Apache or Nginx error logs, displaying new error entries as they occur. Essential for quick identification and debugging of issues on a live web server.

View Snippet →
BASH

Set Up New Web Project Directory with Correct Permissions

Automate the creation of a new web project directory, ensuring proper ownership and read/write permissions for web server access and secure development workflows.

View Snippet →
BASH

Check Server Disk Space and Alert if Low

A bash script to monitor available disk space on a server. It checks all mounted filesystems and alerts if usage exceeds a configurable threshold, preventing outages from full disks.

View Snippet →
BASH

Extract Unique Domain Names from a List of URLs

A powerful bash one-liner to parse a file containing URLs and extract only the unique domain names. Ideal for analyzing web server access logs, link lists, or creating whitelists/blacklists.

View Snippet →
BASH

Gracefully Restart a Web Service and Check Status

A robust bash script to gracefully restart common web services (e.g., Nginx, Apache, PHP-FPM) and verify their running status, minimizing downtime during deployments or configuration changes.

View Snippet →
BASH

Automate Git Pull and Web Project Update

A bash script to automate pulling latest Git changes, installing Node.js dependencies, and building a web project for efficient updates and deployments.

View Snippet →
BASH

Backup a Directory with Timestamp and Cleanup Old Backups

Create timestamped tar.gz backups of a directory and automatically delete backups older than a configurable number of days, saving disk space.

View Snippet →
BASH

Managing Temporary Files and Directories

Securely create and manage temporary files or directories in Bash scripts, ensuring proper cleanup on exit for clean and robust automation.

View Snippet →
BASH

Robust File Existence and Permission Checks

Implement robust file existence and permission checks in Bash scripts using conditional expressions to ensure script reliability and prevent errors.

View Snippet →
BASH

Processing Text Data with awk for Columnar Output

Process and reformat text or log files column-wise using 'awk' in Bash, extracting specific fields and manipulating data efficiently for reports or parsing.

View Snippet →
BASH

Downloading Files Conditionally with curl (If-Modified-Since)

Download files from a URL in Bash using 'curl', conditionally updating only if the remote file is newer, optimizing bandwidth and speeding up deployments.

View Snippet →