Skip to content

Instantly share code, notes, and snippets.

View Aricg's full-sized avatar

Aric Gardner Aricg

View GitHub Profile
@Aricg
Aricg / count in awk .bash
Created May 9, 2013 21:06
count how many gigs all of my snapshots are taking. Whoo boy. It's a lot.
for x in $(find . -type f | grep snapshot | grep eu ); do echo $x; foo=$(cat $x | grep SNAPSHOT | awk '{ i=i+$8}; END { print i }'); echo "$foo GIGS"; done
@Aricg
Aricg / s.bash
Last active December 17, 2015 06:49
ssh screen always.
#ssh into screen allways, if possilbe to a running screen.
#place this script in /usr/bin/s or similar path
#!/bin/bash
function s
{
if [[ "$@" == *@* ]];
then
ssh -t "$@" /usr/bin/screen -xRR
else
@Aricg
Aricg / restart_racoon
Last active December 17, 2015 20:59
restart racoon ipsec vpn if $@ hosts can't be reached
#!/bin/bash
status=0
logdir="/var/log/vpnevent/"
log="vpnevent.log"
#[[ ! $UID = 0 ]] && echo "This script must be run as root"; exit 1
if [[ ! "$1" ]]
then
echo "usage: "$0" List of hosts on which this script depends"
@Aricg
Aricg / gist:5674192
Last active December 17, 2015 21:19
find php shells infecting Wordpress
grep --include=*.php -RPnDskip "(passthru|shell_exec|system|phpinfo|base64_decode|chmod|mkdir|readfile) *\(" .
fgrep -r DQplcnJvcl9yZXBvcnR .
fgrep --include=*.gif -r 'eval' .
fgrep --include=*.gif -r '<?' .
fgrep -r "eval(stripslashes($_REQUEST" .
fgrep -r "46esab" .
fgrep -r "strrev" .
fgrep -r "\x65\x76\x61\x6C" .
fgrep -r "chr(48).chr(43)" .
fgrep -r '*/$' .
@Aricg
Aricg / mongodb
Created May 30, 2013 20:28
actually starts when numactl is present. amazing
#!/bin/sh
#
# init.d script with LSB support.
#
# Copyright (c) 2007 Javier Fernandez-Sanguino <jfs@debian.org>
#
# This is free software; you may redistribute it and/or modify
# it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2,
# or (at your option) any later version.
@Aricg
Aricg / gist:5685819
Created May 31, 2013 15:35
change and push a new hostname to the mongodb cluster.
cluster1:PRIMARY> conf = rs.conf()
{
"_id" : "cluster1",
"version" : 98579,
"members" : [
{
"_id" : 0,
"host" : "shortname001:27017"
},
{
@Aricg
Aricg / check_ping_gateway
Created June 7, 2013 14:43
simple nagios ping gateway check
#!/bin/bash.
host=172.10.10.1
if ! [[ $(ping -c4 $host &> /dev/null;) ]];
then
echo "OK - VPN is up"
else
echo "CRITICAL - Cannot ping VPN gateway"
fi
@Aricg
Aricg / vim.rb
Last active December 27, 2015 19:09 — forked from mgrouchy/vim.rb
require 'formula'
class Vim < Formula
homepage 'http://www.vim.org/'
url 'https://vim.googlecode.com/hg/', :revision => 'c0203d88d1d7'
version '7.3.515'
def features; %w(tiny small normal big huge) end
def interp; %w(lua mzscheme perl python python3 tcl ruby) end
@Aricg
Aricg / gist:7591268
Last active December 29, 2015 01:09
deal with deferred/spammy messages in the postfix queue.
#Removes any deferred messages from the postfix queue if the message has more that 50 recipients. run as root.
su - zimbra -c "mailq" | tail -n +2 | grep -v '^ *(' | awk 'BEGIN { RS=""; }{ if (NF > 50 ) print $1 }' | tr -d '*!' | /opt/zimbra/postfix/sbin/postsuper -d -
#Could be used to detect users sending spam and sent via an email to the administrators.
mailq | tail -n +2 | grep -v '^ *(' | awk 'BEGIN { RS=""; }{ if (NF > 10 ) print $7 }' | tr -d '*!' | sort | uniq -c
example output:
577 foo@bar.com
#Lock accounts that have more than 100 diffrent deffered messages with at least ten recipients in each
for x in $(awk '{if ($1 > 100) print $2}' < <(mailq | tail -n +2 | grep -v '^ *(' | awk 'BEGIN { RS=""; }{ if (NF > 10 ) print $7 }' | tr -d '*!' | sort | uniq )); do \
@Aricg
Aricg / gist:7603876
Last active December 29, 2015 02:58
If the deferred queue has more than 2000 messages and some of those deferred messages have more than 10 recipients this script emails the email address and and number of deferred messages that have over ten recipients to $1
#!/bin/bash
detect_spammers () {
numq=$(su - zimbra -c "mailq" | wc -l)
if (( $numq > 2000 ));
then
echo "number of messages deferred: $numq"
echo "# of messages per user"
sendmail "$@" \
< <(echo -en "spammers detected on host:"; hostname; echo "| # deferred | email@address |"; su - zimbra -c "mailq" | tail -n +2 | grep -v '^ *(' \
| awk 'BEGIN { RS=""; }{ if (NF > 10 ) print $7 }' \