Skip to content

Instantly share code, notes, and snippets.

View ph33nx's full-sized avatar
♠️

ABHI ph33nx

♠️
  • New Delhi
  • 02:13 (UTC +05:30)
View GitHub Profile
@ph33nx
ph33nx / wp-cron.sh
Created July 14, 2024 13:04
Run Cron Jobs in WordPress Using WP CLI (bash Script)
#!/bin/bash
# Run cron jobs for all wordpress sites in a folder using WP CLI.
# Author: https://github.com/ph33nx
# !IMP: Change BASE_DIR below to the folder that has the wordpress sites. Ex: /var/www or /usr/share/nginx etc..
BASE_DIR="/path_to_folder_that_has_wordpress_sites/"
# Check for wp-cli.phar existence in the system
if ! command -v wp &> /dev/null; then
echo "WP-CLI could not be found. Please install it first."
@ph33nx
ph33nx / backup_mysql_db.sh
Last active June 16, 2024 08:30
This bash script automates the process of daily backups for all MySQL/MariaDB databases on a Linux server. It stores each database backup in a dedicated directory under /var/backups/mysql/ and names the backup files using the format <database_name>_<date_time>.sql. Additionally, the script includes a cleanup function that deletes backups older t…
#!/bin/bash
# backup_mysql_db.sh
# This script backs up each MySQL/MariaDB database into its own file daily.
# The backups are stored in /var/backups/mysql/<database_name>/<database_name>_<date_time>.sql
# Backups older than 30 days are automatically deleted.
#
# Author: Ph33nx
# GitHub: https://github.com/ph33nx
#
@ph33nx
ph33nx / wp-update.sh
Last active May 23, 2024 14:13
Wordpress Automated Themes, Plugins & Core Updates - Bash Script - Run as Cron Job
#!/bin/bash
# This script is designed to update WordPress core, plugins, and themes,
# set correct file permissions, and restart Nginx and PHP-FPM services.
# Update www-data user to the filesystem user of WP.
# !IMP: Make sure WP CLI is installed: https://wp-cli.org/
#
# Original script concept by https://github.com/ph33nx
#
# To schedule this script to run every Thursday at 4 AM, add the following line to your crontab:
@ph33nx
ph33nx / fresh-windows-dev-environment.ps1
Last active July 17, 2024 02:06
Setup development environment on Fresh Windows Installation. Run the script in powershell
# On Fresh windows installation, open powershell or terminal and run the script as following:
# powershell.exe -executionpolicy bypass -file .\fresh-windows-dev-enviroment.ps1
winget install -e --id Git.Git
winget install -e --id GitHub.GitLFS
git config --global core.autocrlf false
winget install -e --id Microsoft.VisualStudioCode
winget install -e --id OpenJS.NodeJS.LTS # NodeJS LTS
winget install -e --id Python.Python.3.10 # Python 3.10
@ph33nx
ph33nx / delete_macos_files.ps1
Created February 11, 2024 19:58
Delete hidden MacOS files on Windows using Powershell Script
# Get the current directory
$folder = Get-Location
# Delete hidden files recursively based on pattern
Get-ChildItem -Path $folder -Recurse -Force -File | Where-Object { $_.Name -like "._*" } | ForEach-Object {
# Remove any file attributes
Set-ItemProperty -Path $_.FullName -Name Attributes -Value 0
# Attempt to delete the file
Remove-Item -Path $_.FullName -Force
}
@ph33nx
ph33nx / fresh-mac-dev-environment.sh
Last active July 13, 2024 03:18
Fresh Mac OS Development Environment setup - bash script
#!/bin/bash
# Install Homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
(echo; echo 'eval "$(/opt/homebrew/bin/brew shellenv)"') >> ~/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
brew analytics off
@ph33nx
ph33nx / lemp-ubuntu.sh
Last active May 23, 2024 15:53
LEMP stack on Ubuntu 24.04 LTS (2024): Automated Bash Script for Installing Nginx, Php 8.3, WordPress, Mysql/Mariadb
#!/bin/bash
# This script is meant to be run on a fresh Ubuntu 24.04 LTS installation.
# Tired of manually installing LEMP stack on Ubuntu? This script will do it for you.
#
# Optionally, This script restores a server from a backup. It assumes the following directory structure:
# - backup/
# - nginx/ (contains nginx configuration files)
# - db/ (contains .sql files for database restoration)
# - sites.zip (zipped file containing site files)
@ph33nx
ph33nx / adobe_exe_firewall_block_windows.bat
Last active July 19, 2024 14:55
Block All Adobe .exe files via Firewall on Windows Using Batch Script | Stop adobe apps to access internet
@REM Author: https://github.com/ph33nx
@REM Description: This script blocks or unblocks Adobe-related executables in Windows Firewall.
@REM Usage:
@REM - To block executables: adobe_block.bat
@REM - To unblock (delete) existing rules: adobe_block.bat -delete
@echo off
setlocal enabledelayedexpansion
REM Check if the script should delete existing rules
@ph33nx
ph33nx / windows_firewall_block_exe.bat
Last active July 10, 2024 10:33
Windows Firewall - Block All .Exe's Inside a folder from accessing Internet using batch script | Block all .exe in a folder to access Internet
@REM This batch script loops through all exe's inside a directory and blocks all .exe's inside that folder and its subfolders using windows inbuilt firewall.
@REM IMP: Replace FOLDER_NAME with the folder in which you want all .exe's blocked. or replace the whole url, for ex: C:\Program Files\Adobe
@ setlocal enableextensions
@ cd /d "%~dp0"
@for /R "C:\Program Files\FOLDER_NAME" %%a in (*.exe) do (
netsh advfirewall firewall add rule name="%%~na (Blocked using script)" dir=out program="%%a" action=block
@ph33nx
ph33nx / postgres-daily-backup.sh
Last active April 3, 2023 13:59
Postgres Daily Backup Bash Script + Get Credentials from .env
# This script is used to backup postgresql database to a file
# 1. Keep the backup file for 30 days
# 2. Intended to be run from cron
# 3. Read DB credentials from .env file next to the script
# 4. Restore the backup with the following command in psql
# PGPASSWORD=$DB_SECRET pg_restore -Fc --no-owner -h localhost -p 5432 -U $DB_USERNAME -d $DB_NAME < $BACKUP_FILE_NAME
# cd to the script directory
cd "$(dirname "$0")"