Skip to content

Instantly share code, notes, and snippets.

@Sam-R
Sam-R / database_backup.sh
Created July 7, 2021 12:26
backup non system mysql databases for rsnapshot to pickup with a backup user
#!/bin/bash
OUTPUT_DIR=/root
BACKUP_USER=backupuser
BACKUP_DIR=/home/backupuser/
# Identify the databases on this server
databases=$(mysql -s -r -N -e 'show databases where `Database` not in("information_schema", "performance_schema", "accounts", "mysql", "sys")')
for database in $databases; do
@Sam-R
Sam-R / extract_ips.sh
Created June 23, 2021 12:09
Extract IPv4 addresses from /etc/hosts file
cat /etc/hosts | grep -Eo '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' | awk '{ print $1 }'
@Sam-R
Sam-R / load_trustpilot.php
Created September 16, 2020 09:31
Get the number of stars from a given TrustPilot page using PHP
<?php
// Webpage to load
$url = "https://uk.trustpilot.com/review/your-page-here";
// Contents of webpage
$contents = file_get_contents($url);
// Declair a new DOM
$doc = new DOMDocument('1.0', 'UTF-8');
@Sam-R
Sam-R / php_docker_basic.md
Last active April 2, 2020 17:37
basic docker-compose setup with nginx and php-fpm container pair

Create a basic PHP and nginx container pair, mounting their local working directory.

docker-compose.yml

version: '3'

services:
    nginx:
@Sam-R
Sam-R / ansible_notes.md
Created October 17, 2019 14:23
Ansible notes

Ansible notes

plays

tasks actions to take inside a play

registers capture output from a task

handlers handle errors and can execute an action

@Sam-R
Sam-R / postfix-queue-delete-connection-error-mails.md
Created October 16, 2019 17:33 — forked from jkullick/postfix-queue-delete-connection-error-mails.md
Delete Connection Error Mails from Postfix Queue
mailq | \
  grep -E "Connection (refused|timed out)" -B1 | \
  grep -E "^[A-Z0-9]{11}\s+" | \
  awk '{print $1}' | \
  postsuper -d -
@Sam-R
Sam-R / postfix-queue-delete-connection-error-mails.md
Created October 16, 2019 17:33 — forked from jkullick/postfix-queue-delete-connection-error-mails.md
Delete Connection Error Mails from Postfix Queue
mailq | \
  grep -E "Connection (refused|timed out)" -B1 | \
  grep -E "^[A-Z0-9]{10}\s+" | \
  awk '{print $1}' | \
  postsuper -d -
@Sam-R
Sam-R / gist:0cf2a1d04bf0247bb37fc75150920c6a
Created September 16, 2019 13:22
compare two sorted files for any differences
grep -v -F -x -f file_sorted.csv file2_sorted.csv
@Sam-R
Sam-R / Docker Dev.md
Created June 13, 2019 11:25
Docker Development Environment Notes

MySQL

Create a MySQL instance in a docker container that's bound to the hosts standard MySQL ports. This is useful if you're developing locally without a docker-compose enviornment and don't want to run MySQL on your local or virtual machine.

sudo docker run --name mysql5 -e MYSQL_ROOT_PASSWORD=toor -P 3306:3306 -d mysql:5

You should be able to connect to the server using root and toor as credentials.

@Sam-R
Sam-R / NextCloud Fail2Ban.md
Created May 31, 2019 20:05
Fail2Ban config for NextCloud

sudo nano /etc/fail2ban/filter.d/nextcloud.conf

[Definition]
failregex=^{"reqId":".*","remoteAddr":".*","app":"core","message":"Login failed: '.*' \(Remote IP: '<HOST>'\)","level":2,"time":".*"}$
	^{"reqId":".*","level":2,"time":".*","remoteAddr":".*","app":"core".*","message":"Login failed: '.*' \(Remote IP: '<HOST>'\)".*}$
	^.*\"remoteAddr\":\"<HOST>\".*Trusted domain error.*$