Skip to content

Instantly share code, notes, and snippets.

View Aricg's full-sized avatar

Aric Gardner Aricg

View GitHub Profile
@Aricg
Aricg / iostatparse
Last active December 15, 2015 14:19
parses iostat to give iowait, reads and writes (Blk_read Blk_wrtn) in a specific way that I wanted it to at one point on some day or other.
#!/bin/bash
vg=vg_backup-lv_backup
numlines=50
geta() {
a=()
while read -d $'\n'; do
a+=("$REPLY")
done < <(echo "$@" | tail -n 6| grep -A2 iowait | awk '{ print $4 }' | sed 's,\,,,g' | grep -o '[0-9]*' | sed 's/.$//')
}
@Aricg
Aricg / gist:5294986
Created April 2, 2013 18:44
parses iostat to show sectors written per second vs the queue of reads/writes pending. Specific to my purposes. Go away ;)
#!/bin/bash
sda=sda
numlines=60
outputr=$1
outputw=$2
getread() {
a=()
while read -d $'\n'; do
a+=("$REPLY")
@Aricg
Aricg / gist:5357574
Created April 10, 2013 19:13
finds zgipped log files log."$1".gz and then counts and adds all of their lines. split into error and access.
#!/bin/bash
getlog() {
log=()
while read -d $'\n'; do
log+=("$REPLY")
done < <(find /var/log/apache2/* -type f | grep log."$1".gz | grep "$2" error )
}
manupilatelogs() {
@Aricg
Aricg / gist:5375218
Created April 12, 2013 21:21
watch a log file, echo anything it produces into a fifo
#!/bin/bash
search_str="$1"
pipe=/tmp/alert
trap "rm -f $pipe" EXIT
rm -f $pipe
if [[ ! -p $pipe ]]; then
mkfifo $pipe
fi
@Aricg
Aricg / tail nagios
Last active December 16, 2015 06:19
tails a log and if certain stings are found it prints all but the first four parts of the line.
#!/usr/bin/python
from sh import tail
import string
for line in tail("-fn0", "/tmp/alert", _iter=True):
if ("PASSIVE" and "OK") in line:
nagios_alerts = line.split(" ")
print repr(nagios_alerts[4:])
print(len(nagios_alerts[4:]))
@Aricg
Aricg / sidekiq
Created April 18, 2013 14:37 — forked from dyerc/sidekiq
#!/bin/bash
# sidekiq Init script for Sidekiq
# chkconfig: 345 100 75
#
# Description: Starts and Stops Sidekiq message processor for Stratus application.
#
# User-specified exit parameters used in this script:
#
# Exit Code 5 - Incorrect User ID
# Exit Code 6 - Directory not found
@Aricg
Aricg / gist:5470931
Last active December 16, 2015 17:29
Uses ec2-describe-snapshots and ec2-delete-snapshot to order and delete snapshosts for a given account. to be used with https://gist.github.com/Aricg/5482068
#!/bin/bash
numbertokeep=15
for zone in $(cat tmp_zones)
do
for x in $(find /home/ubuntu/KEYS/* -type f | grep ".key");
do
key="--region "$zone" -C ${x%.*}.pem -K ${x%.*}.key"
@Aricg
Aricg / snapshot all volumes
Last active December 16, 2015 19:00
uses ec2-create-snapshot ec2-describe-instances and some awk to make a snapshot for each attached volume in any number of ec2 environments and across all availability zones . Assumes keys are in $KEYDIR and are named foo.key and foo.pub
#!/bin/bash
#########################
# How to use
# Naviage to the aws/securityCredentials page and generate a x.509 certificate
# take both the public and the private certificate file and place them in $KEYDIR
# rename the public and private certificate foo.pub and foo.key respectivly
# you may provide this script with any number of certificate pairs
#
# What it does
# This script takes a SNAPSHOT of all ATTACHED volumes across all AVALIABILITY zones.
@Aricg
Aricg / gist:5497208
Last active December 16, 2015 21:09
Personal reference next time I use awk for other than print $x field
Gondrol
2321
56
58
45
RinRao
2122
38
37
@Aricg
Aricg / inventory aws
Last active December 16, 2015 23:21
ec2-describe-instances ec2-describe-volumes and ec2-describe-snapshots for x environments all availability zones. assumes keys are in /home/ubuntu/KEYS/* and names foo.key and foo.pem Also counts size in gigs of attached volumes as well as all snapshots.
#!/bin/bash
for x in $(find /home/ubuntu/KEYS/* -type f | grep ".key");
do
#Get a list of avaliable avaliablility zones
if [[ ! -e tmp_zones ]]; then
ec2-describe-regions -C ${x%.*}.pem -K ${x%.*}.key | awk '{ print $2 }' > tmp_zones
fi
for zone in $(cat tmp_zones)