Skip to content

Instantly share code, notes, and snippets.

View tperalta82's full-sized avatar

Tiago Peralta tperalta82

View GitHub Profile
#!/bin/bash
DATABASES_TO_EXCLUDE="db1 db2 db3"
EXCLUSION_LIST="'information_schema','mysql','performance_schema'"
for DB in `echo "${DATABASES_TO_EXCLUDE}"`
do
EXCLUSION_LIST="${EXCLUSION_LIST},'${DB}'"
done
SQLSTMT="SELECT schema_name FROM information_schema.schemata"
SQLSTMT="${SQLSTMT} WHERE schema_name NOT IN (${EXCLUSION_LIST})"
MYSQLDUMP_DATABASES="--databases"
@tperalta82
tperalta82 / httpd-check.sh
Created September 22, 2016 01:32
Simple http-checker
#!/bin/bash
WBSRV=$(/usr/bin/timeout 10 /usr/bin/curl --verbose --header 'Host: pornhub.com' 'http://localhost/' -m 10 -f --silent > /dev/null 2>&1)
WBSRVSTAT=$?
SSTAT=$(/sbin/service httpd status)
LRET=$?
if [ $WBSRVSTAT -ne 0 ] || [ $LRET -ne 0 ]; then
subject="Apache Server Down / Unresponsive";
recipients="[email protected],[email protected]"
message="Apache Service is down or not responding, restarting service, if it fails to restart or if you receive this message again in 1 minute, please check with your awesome sysadmins!
@tperalta82
tperalta82 / mysql-check.sh
Created September 21, 2016 16:16
Simple Mysql check/restart
#!/bin/bash
MSCONN=$(echo "SHOW GLOBAL STATUS LIKE 'Uptime';" | mysql -pyoursupersecurepasswordthatnotevengodknows)
CONSTAT=$?
SSTAT=$(service mysqld status)
LRET=$?
if [ $CONSTAT -ne 0 ] || [ $LRET -ne 0 ]; then
subject="Mysql Server Down / Unresponsive";
recipients="[email protected],thisoneisnot@nopecom"
<?php
/**
* class CIDR.
* Holds static functions for ip address manipulation.
*/
class CIDR {
/**
* method CIDRtoMask
* Return a netmask string if given an integer between 0 and 32. I am
<?php
/**
* CIDR.php
*
* Utility Functions for IPv4 ip addresses.
* Supports PHP 5.3+ (32 & 64 bit)
* @author Jonavon Wilcox <[email protected]>
* @revision Carlos Guimarães <[email protected]>
* @version Wed Mar 12 13:00:00 EDT 2014
*/
@tperalta82
tperalta82 / apachesplit.php
Created June 23, 2016 16:38
Apache Vhost Split
<?php
/**
* Description of index
* @copyright Copyright (c) 2016 FRK Agency. All rights reserved
* @author Tiago Peralta <[email protected]>
*/
if (!isset($argv[1]) || !is_file($argv[1])) {
die("Please specify an input file, preferably one that exists. e.g. php split.php vhosts.conf exportdir(optional) ");
}
@tperalta82
tperalta82 / nginx.sh
Created June 23, 2016 16:38
Nginx Split vhosts
#!/bin/bash
if [ ! -d "ngxvhosts" ]; then
mkdir ngxvhosts
fi
if [ -f "xx*" ]; then
rm xx*
fi
echo $1 $2 $3
csplit nginx.conf '/\s*\<server\>\s*/' {*}
@tperalta82
tperalta82 / openresty
Created May 25, 2016 17:32
openresty init.d
#!/bin/sh
### BEGIN INIT INFO
# Provides: openresty
# Required-Start: $local_fs $remote_fs $network $syslog $named
# Required-Stop: $local_fs $remote_fs $network $syslog $named
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts openresty
# Description: starts openresty using start-stop-daemon
@tperalta82
tperalta82 / splitvhosts.php
Last active April 18, 2016 16:35
Split an ugly multiple vhost file to multiple files
<?php
if (!isset($argv[1]) || !is_file($argv[1])) {
die("Please specify an input file, preferably one that exists. e.g. php split.php vhosts.conf exportdir(optional) ");
}
if (isset($argv[2]) && is_dir($argv[2])) {
$dir = realpath($argv[2]).DIRECTORY_SEPARATOR;
} else {
echo "No Export dir specified, or non existent one, using default".PHP_EOL;
$dir = getcwd().DIRECTORY_SEPARATOR."vhosts".DIRECTORY_SEPARATOR;
@tperalta82
tperalta82 / nginx-pagespeed.spec
Last active March 16, 2016 18:25
Spec file to build nginx with google pagespeed under amazon linux
%define _buildid .26
%bcond_with systemd
%global _hardened_build 1
%global nginx_user nginx
%global nginx_group %{nginx_user}
%global nginx_home %{_localstatedir}/lib/nginx
%global nginx_home_tmp %{nginx_home}/tmp
%global nginx_confdir %{_sysconfdir}/nginx