Skip to content

Instantly share code, notes, and snippets.

@jsonUK
jsonUK / profile.sh
Created November 8, 2019 11:58
Email alert every time someone logs into a VPS box/server via SSH
# Place this at the bottom of your /etc/profile file
if [ -n "$SSH_CLIENT" ]; then
TEXT="$(date): ssh login to ${USER}@$(hostname -f)"
TEXT="$TEXT from $(echo $SSH_CLIENT|awk '{print $1}')"
echo $TEXT|mail -s "ssh login" myemail@example.com
fi
@jsonUK
jsonUK / Bash - New MySQL DB & User
Last active October 3, 2019 11:19
Fix the character set to be utf8mb4 and utf8mb4_unicode_ci.
#!/bin/bash
# create random password
PASSWD="$(openssl rand -base64 30)"
PASSWD_STAGE="$(openssl rand -base64 30)"
echo -e "\033[36mEnter DB name (domain name):\033[0m"
read db_name
echo -e "\033[36mEnter Username:\033[0m"
@jsonUK
jsonUK / tab-autocomplete-ssh.sh
Created June 14, 2018 15:06
Tab auto-complete your ssh configs in your terminal on scp ssh etc.
# Tab autocomplete ssh hosts
h=()
if [[ -r ~/.ssh/config ]]; then
h=($h ${${${(@M)${(f)"$(cat ~/.ssh/config)"}:#Host *}#Host }:#*[*?]*})
fi
#if [[ -r ~/.ssh/known_hosts ]]; then
# h=($h ${${${(f)"$(cat ~/.ssh/known_hosts{,2} || true)"}%%\ *}%%,*}) 2>/dev/null
#fi
if [[ $#h -gt 0 ]]; then
zstyle ':completion:*:ssh:*' hosts $h
@jsonUK
jsonUK / mmonit.conf
Created February 13, 2018 11:19
MMonit Fail2ban
# Fail2Ban configuration file for M/Monit ( mmonit )
# Author: eXtremeSHOK.com
# $Revision: 101 $
[Definition]
# Option: failregex
# Notes.: regex to match the password failure messages in the logfile. The
# host must be matched by a group named "host". The tag "" can
# be used for standard IP/hostname matching and is only an alias for
@jsonUK
jsonUK / woocommerce.php
Created September 3, 2017 16:03
Change WooCommerce input fields to have Bootstrap form-control class
add_filter('woocommerce_form_field_args', 'addBootstrapInputClass', 10, 3);
function addBootstrapInputClass($args, $key, $value) {
$args['input_class'] = ['form-control'];
return $args;
}
@jsonUK
jsonUK / get-domain-cert-by-dns.txt
Last active August 24, 2017 11:04
Get Letsencrypt to use a DNS challenge for generating certs
/opt/letsencrypt/letsencrypt-auto -d subdomain.example.com --manual --preferred-challenges dns certonly
@jsonUK
jsonUK / clear-opcache
Created August 21, 2017 16:57
Clear the OpCache via the console
#!/bin/sh
# Gracefully Restart PHP7 FPM with SIGUSR2
# This clears PHP5 OpCache
if (kill -s USR2 `cat /var/run/php/php7.0-fpm.pid`) then
echo "Cleared PHP OpCache"
fi
@jsonUK
jsonUK / Emmet.sublime-settings
Created August 20, 2017 18:12
Emmet settings to show classname/ids after the closing element
{
"preferences": {
"filter.commentAfter": "<!-- /<%= attr(\"id\", \"#\") %><%= attr(\"class\", \".\") %> -->"
},
"syntaxProfiles": {
"html": {
"filters": "html,c"
}
}
}
@jsonUK
jsonUK / wp-new.sh
Last active April 17, 2023 20:02
Script to create new WordPress setup, using WP-CLI
#!/bin/bash
#
# USE FOR LOCAL DEVELOPMENT ONLY!!!
#
EMAIL='your-email@gmail.com'
MYSQL=`which mysql`
echo -n "DB user/name for project (lowercase) [ENTER]:"
read DB
@jsonUK
jsonUK / svnurl.sh
Created November 23, 2012 15:44 — forked from westonruter/svnurl.sh
Echo and pbcopy the URL for the given SVN working copy
#!/bin/bash
# Prints and copies to the clipboard the SVN URL of the current working
# directory or the first command line argument
# by @westonruter; use of awk and tr thanks to @josh_wnj
if [ $# == 0 ]; then
cwd=`pwd`
else
cwd="$1"
fi