Anonymous avatar Anonymous committed c63c4f7

initial commit

Comments (0)

Files changed (17)

+generic-bash-scripts
+====================
+
+Various bash scripts for sysadmin, dba, etc
+[streaming-write]
+rw=write
+size=12g
+directory=/data
+iodepth=1
+blocksize=1024k
+numjobs=1
+nrfiles=1
+loops=1
+create_serialize=0
+group_reporting
+
+[streaming-readwrite]
+stonewall
+create_serialize=0
+loops=1
+rw=rw
+size=12g
+directory=/data
+iodepth=1
+direct=0
+blocksize=1024k
+numjobs=1
+nrfiles=1
+group_reporting
+
+
+[streaming-read]
+stonewall
+create_serialize=0
+loops=1
+rw=read
+size=12g
+directory=/data
+iodepth=1
+direct=0
+blocksize=1024k
+numjobs=1
+nrfiles=1
+group_reporting

convert_sql-to-sqlite3.sh

+#!/bin/sh
+if [ "x$1" == "x" ]; then
+   echo "Usage: $0 <dumpname>"
+   exit
+fi
+cat $1 |
+grep -v ' KEY "' |
+grep -v ' UNIQUE KEY "' |
+grep -v ' PRIMARY KEY ' |
+sed '/^SET/d' |
+sed 's/ unsigned / /g' |
+sed 's/ auto_increment/ primary key autoincrement/g' |
+sed 's/ smallint([0-9]*) / integer /g' |
+sed 's/ tinyint([0-9]*) / integer /g' |
+sed 's/ int([0-9]*) / integer /g' |
+sed 's/ character set [^ ]* / /g' |
+sed 's/ enum([^)]*) / varchar(255) /g' |
+sed 's/ on update [^,]*//g' |
+perl -e 'local $/;$_=<>;s/,\n\)/\n\)/gs;print "begin;\n";print;print "commit;\n"' |
+perl -pe '
+  if (/^(INSERT.+?)\(/) {
+     $a=$1;
+     s/\\'\''/'\'\''/g;
+     s/\\n/\n/g;
+     s/\),\(/\);\n$a\(/g;
+  }
+  ' > $1.sql
+cat $1.sql | sqlite3 $1.db > $1.err
+ERRORS=`cat $1.err | wc -l`
+if [ $ERRORS == 0 ]; then
+  echo "Conversion completed without error. Output file: $1.db"
+  rm $1.sql
+  rm $1.err
+    rm tmp
+else
+   echo "There were errors during conversion.  Please review $1.err and $1.sql for details."
+fi
+#!/bin/sh
+USERNAME="mreid"
+if test -z $1
+then
+    echo "you must specify a hostname or ip address as the first argument"
+    exit 1
+fi
+key=`cat ~/.ssh/id_dsa.pub`
+ssh $USERNAME@$1 "mkdir -p ~/.ssh && chmod 700 ~/.ssh && echo \"$key\" >> ~/.ssh/authorized_keys && chmod 644 ~/.ssh/authorized_keys"
+if [ $? = "0" ]; then
+    echo "key copy successful"
+else
+    echo "key copy failed"
+fi
+#!/bin/sh
+echo ">>>> Shell Copy >>>>"
+echo ""
+HOST=$1
+BIN=`which scp`
+if test -z $HOST
+then
+    echo "You must specify a hostname or ip address as the first argument"
+    exit 1
+fi
+
+echo "Starting copy process for host: $HOST"
+FILES=".bashrc .emacs .emacs.d .bash_logout .bash_profile"
+for file in $FILES; do
+    cd $HOME
+    echo -n "Copying file[$file]: "
+    flag=''
+    if [ -d $file ]; then flag=-r; fi
+    echo "$BIN $flag $file $HOST:."
+    $BIN $flag $file $HOST:.
+    if [ $? -ne 0 ]; then
+	echo "[FAILED]"
+	exit 2
+    fi
+    echo "[OK]"
+done
+
+#echo -n "Copy .my.cnf file as well? [y,N]"
+#if [ "$REPLY" = y ]; then
+#    echo -n "Copying file[$file]: "
+#    $BIN ~/.my.cnf $HOST:.
+#fi
+
+echo ""
+echo "Finished copying shell files to host: $HOST"
+echo ""
+exit 0
+#!/bin/sh
+# Date: 2011-07-29, update: 2012-04-23
+# Author: Matt Reid
+# Function: Decrypts and Encrypts files
+
+function generate_digests() {
+    echo "  Input file: $filein"
+    openssl dgst -md5 $1
+    echo "  Output file: $fileout"
+    openssl dgst -md5 $2
+}
+
+function header() {
+    echo " -------------------------------- "
+    echo "|CryptR | security for the masses|"
+    echo " -------------------------------- "
+    echo "m.reid 2012.04.23 ver 2.68        "
+    echo ""
+}
+
+function help() {
+    echo "Purpose: Encrypts and Decrypts files via AES-256"
+    echo "  -e, --encrypt       encrypt the file"
+    echo "  -d, --decrypt       decrypt the file"
+    echo "  -i, --input         input file to read"
+    echo "  -o, --output        output file to write"
+    echo ""
+}
+
+## Start GetOpt stuff
+encrypt="no"    #encrypt function state (e,encrypt)
+decrypt="no"    #decrypt function state (d,decrypt)
+filein="no"   #filename IN flag (i,input)
+fileout="no"  #filename OUT flag (o,output)
+
+while [ $# -gt 0 ]; do
+    case $1 in
+        -e|--encrypt) encrypt="yes" ;;
+        -d|--decrypt) decrypt="yes" ;;
+        #long opts need additional shift
+        -i|--input) filein="$2" ; shift;;
+        -o|--output) fileout="$2" ; shift;;
+        (--) shift; break;;
+        (-*) echo "$0: error - unrecognized option $1" 1>&2; exit 1;;
+        (*) break;;
+    esac
+    shift
+done
+## End GetOpt
+
+## Secure delete process
+function sdelete() {
+    if [ $(uname -s) == 'Darwin' ]; then
+        srm $1
+    elif [ $(uname -s) == 'Linux' ]; then
+        shred -u $1
+    fi
+}
+
+## Decrypt Process
+function decrypt() {
+    filein="$1"
+    fileout="$2"
+    if [ "$filein" = "no" ]; then
+        echo -n "No encrypted file specified, what file are we decrypting: "
+        read filein
+    fi
+
+    if [ -r "$filein" ]; then
+        if [ "$fileout" = "no" ]; then
+            fileout="$filein.decrypted"
+        fi
+        openssl enc -d -aes256 -in $filein -out $fileout
+        generate_digests $filein $fileout
+        exit 0;
+    else
+        echo "File '$filein' is not readable or does not exist."
+        exit 1;
+    fi
+}
+
+## Encrypt Process
+function encrypt() {
+    filein="$1"
+    fileout="$2"
+    if [ "$filein" = "no" ]; then
+        echo -n "No input file specified, what file are we encrypting: "
+        read filein
+    fi
+
+    if [ -r "$filein" ]; then
+        if [ "$fileout" = "no" ]; then
+            fileout="$filein.aes256"
+        fi
+        if [ -f "$fileout" ]; then
+            echo "Output file exists already, encrypting will overwrite this file."
+            echo -n "Do you want to encrypt anyway? [Y/n]: "
+            read choice
+            if [ "$choice" = "Y" ] || [ "$choice" = "y" ] || [ "$choice" = "" ]; then
+                openssl enc -aes256 -in $filein -out $fileout
+                generate_digests $filein $fileout
+                sdelete $filein
+                exit 0;
+            else
+                exit 2;
+            fi
+        else
+            openssl enc -aes256 -in $filein -out $fileout
+            generate_digests $filein $fileout
+            sdelete $filein
+            exit 0;
+        fi
+    else
+        echo "Input file does not exist or is not readable. You're attempting to encrypt file: '$filein'"
+        exit 1;
+    fi
+}
+
+if [ "$encrypt" = "yes" ] && [ "$decrypt" = "no" ]; then
+    encrypt $filein $fileout
+elif [ "$decrypt" = "yes" ] && [ "$encrypt" = "no" ]; then
+    decrypt $filein $fileout
+else
+    #clear
+    header
+    help
+fi
+
+#!/bin/sh
+
+# spitter - splits a file into parts for parallel transfer
+
+test "$4" || { echo "usage: $0 filename chunksize remote-host remote-dir"; exit 1; }
+
+INFILE=$1
+CHUNKSIZE=$2
+REMOTEHOST=$3
+REMOTEDIR=$4
+
+test -s ${INFILE} || { echo "File is inaccessible or zero length"; exit 1; }
+test -w $PWD || { echo "No write permission on current directory."; exit 1; }
+#test -f combine.sh || { echo "Cannot find combine.sh. Aborting."; exit 1; }
+
+# see if we can reach the remote host
+ping -c 1 -W 5 $REMOTEHOST >/dev/null 2>/dev/null
+test $? -eq 0 || { echo "Unable to ping $REMOTEHOST"; exit 1; }
+
+#echo "local md5: `md5sum ${INFILE}`"
+#md5sum -b ${INFILE} >${INFILE}.md5
+
+split --bytes=${CHUNKSIZE} --numeric-suffixes $1 $1.split.
+test $? -eq 0 || { echo "Error during split. Make sure you use a chunk size that results in 100 or fewer chunks. Aborting."; exit 1; }
+
+echo "parallel scp started - see scp.log for progress."
+echo "run combine.sh on other side when xfer completed."
+
+# send over the recombination script
+./scpwrap.sh combine.sh ${REMOTEDIR} ${REMOTEHOST}
+
+for i in `ls ${INFILE}.split.*`; do
+  ./scpwrap.sh $i ${REMOTEDIR} ${REMOTEHOST} >> scp.log &
+  sleep 1   ## slight pause
+done
+#./scpwrap.sh ${INFILE}.md5 ${REMOTEDIR} ${REMOTEHOST} >> scp.log

files_check_setuid.sh

+#!/bin/sh
+
+#find SUID and SGID files
+echo "Finding SUID and SGID files..."
+sudo find / \( -perm -4000 -o -perm -2000 \) -type f -exec file {} \; | grep -v ELF
+
+#find SUID and SGID directories
+echo "Finding SUID and SGID directories..."
+sudo find / -type d \( -perm -g+w -o -perm -o+w \) -exec ls -lad {} \;
+
+#check for listening sockets
+echo "Checking for listening sockets..."
+sudo netstat -luntp

infosec_controlshell.sh

+#!/bin/bash
+NAME="Auditcontrol Menu v2.1"
+#runs security programs:
+#nmap, nessus, nikto, ghba, dnascan, dig, whois for auditing purposes
+#by Matt Reid matthew@servepath.com / themattreid@gmail.com
+
+##################################
+#MY SHELL - LOCAL SCANNER
+##################################
+
+#Set file locations - modify as needed
+#ROOTDIR is where nikto/dna/ghba progs live
+ROOTDIR="/home/adminsp/security"
+REPORTDIR="/home/adminsp/reports"
+DIG=`which dig`
+GHBA="$ROOTDIR/ghba"
+WHOIS=`which whois`
+NIKTO="$ROOTDIR/nikto/nikto.pl"
+NIKTOCONFIG="$ROOTDIR/nikto/config.txt"
+DNASCAN="$ROOTDIR/dnascan.pl"
+NESSUS=`which nessus`
+NMAP=`which nmap`
+NESSUSUSER="adminsp"
+NESSUSPASS="1980isahardONE"
+NESSUSIP="localhost"
+NESSUSPORT="1241"
+DATE=`date +"%a.%b.%Y.%T"`
+UNIXDATESTART=`date +"%s"`
+FINALREPORT="$REPORTDIR/Audit.Report_CRID=$CRID.$DATE"
+
+################################
+#these args are no longer in use
+HOST=$2
+EMAIL=$3
+CRID=$4
+################################
+
+#begin scanning functions
+#
+function write2file {
+    echo -n  "Save report to file? [no]: "
+    read CONFIRM
+    if [ "$CONFIRM" = "" ]; then
+        echo "Not saving file."
+	echo ""
+    elif [ "$DISPLAYREPORT" = "no" ]; then
+        echo "Not saving file."
+	echo ""
+    else
+        echo -n "Save file as: "
+	read SAVEAS
+	touch $SAVEAS && cat $FINALREPORT > $SAVEAS
+    fi
+}
+
+function scanTime {
+    UNIXDATEEND=`date +"%s"`
+    SCANTOTAL=$(($UNIXDATEEND - $UNIXDATESTART))
+    echo ""
+    echo "Scan took this many seconds: $SCANTOTAL"
+}
+
+function email {
+        #redefine $DATE to get current time
+        DATE=`date +"%a.%b.%Y.%T"`
+        MAILREPORT=`mail -v -s "Audit Report for $CRID / $IPADDRESS / $HOST on $DATE" $EMAIL < $FINALREPORT`
+        echo "Emailed report: [$FINALREPORT] to [$EMAIL] on $DATE"
+}
+
+function display {
+        echo ""
+        echo -n "Press ENTER for report. "
+	read NULLVAR
+	clear
+	echo ""
+	echo "##########################"
+	echo ""
+        cat $FINALREPORT
+	echo ""
+	echo "##########################"
+	echo ""
+}
+
+function reporter {
+    if [ "$EMAIL" = "" ]; then
+	scanTime
+	display
+	write2file
+    else 
+    echo -n "Display Report? [no]"
+    read DISPLAYREPORT
+        if [ "$DISPLAYREPORT" = "" ]; then
+	    scanTime
+	    email
+	elif [ "$DISPLAYREPORT" = "no" ]; then
+	    scanTime
+	    email
+	else 
+	    scanTime
+	    email
+	    display
+	    write2file
+	fi
+    fi
+}
+
+function nmapPing {
+    REPORTNAME="$REPORTDIR/nmap.ping.report_$CRID_.$DATE.nor"
+    echo "Running NMap Ping Scan...."
+    scan=`sudo $NMAP -sP -v -oN $REPORTNAME $IPADDRESS`
+    echo "#### NMAP PING SCAN ####" >> $FINALREPORT
+    cat $REPORTNAME >> $FINALREPORT
+}
+
+function nmapStealth {
+    REPORTNAME="$REPORTDIR/nmap.stealth.report_$CRID_.$DATE.nor"
+    echo "Running NMap Stealth Port Scan..."
+    scan=`sudo $NMAP -sS -v -T Aggressive -O -oN $REPORTNAME $IPADDRESS`
+    echo "#### NMAP STEALTH SCAN ####" >> $FINALREPORT
+    cat $REPORTNAME >> $FINALREPORT
+}
+
+function niktoScan {
+    REPORTNAME="$REPORTDIR/nikto.report_$CRID_.$DATE.html"
+    #Faster scan =>20 minutes 
+    echo "Running Nikto Web Vuln Scan... this could take a while."
+    scan=`$NIKTO -config $NIKTOCONFIG -cookies -Format htm -o $REPORTNAME -host $IPADDRESS`
+    #Slow scan but very thorough - I'm talking hours!
+    #echo "Running Nikto Web Vuln Scan. This is the long one!
+    #scan=`$NIKTO -config $NIKTOCONFIG -cookies -Cgidirs all -evasion 9 -Format htm -o $REPORTNAME -host $IPADDRESS`
+    echo "#### NIKTO SCAN ####" >> $FINALREPORT
+    cat $REPORTNAME >> $FINALREPORT
+}
+
+function nessusScan {
+    REPORTNAME="nessus.report.txt"
+    HOSTFILE="$REPORTDIR/nessus_IP_Scan_$CRID_.$DATE.foo"
+    HOST2SCAN=`echo $IPADDRESS > $HOSTFILE`
+    echo "Running Nessus Scan... this could take a while."
+    scan=`$NESSUS -q -T txt $NESSUSIP $NESSUSPORT $NESSUSUSER $NESSUSPASS $HOSTFILE $REPORTNAME`
+    rm $HOSTFILE
+    echo "#### NESSUS SCAN ####" >> $FINALREPORT
+    cat $REPORTNAME >> $FINALREPORT
+}
+
+function dnaScan {
+    REPORTNAME="$REPORTDIR/DNA_$CRID_report.$DATE.txt"
+    echo "Running DNA Scan..."
+    scan=`$DNASCAN http://$IPADDRESS > $REPORTNAME`
+    echo "#### DNA SCAN ####" >> $FINALREPORT
+    cat $REPORTNAME >> $FINALREPORT
+}
+
+function ghbaScan {
+    REPORTNAME="$REPORTDIR/GHBA_$CRID_report.$DATE.txt"
+    echo "Running GHBA Scan..."
+    scan=`$GHBA $IPADDRESS -f $REPORTNAME`
+    echo "#### GHBA SCAN ####" >> $FINALREPORT
+    cat $REPORTNAME >> $FINALREPORT
+}
+
+function whoisScan {
+    if [ "$HOST" = "" ]; then
+	echo "Hostname NULL, Not running WHOIS Scan."
+    else
+	REPORTNAME="$REPORTDIR/WhoIS_$CRID_report.$DATE.txt"
+	echo "Running WhoIS Scan..."
+	scan=`$WHOIS $HOST > $REPORTNAME`
+	echo "#### WHOIS SCAN ####" >> $FINALREPORT
+	cat $REPORTNAME >> $FINALREPORT
+    fi
+}
+
+function digScan {
+    if [ "$HOST" = "" ]; then
+	echo "Hostname NULL, not running DIG Scan."
+    else
+	REPORTNAME="$REPORTDIR/Dig_$CRID_report.$DATE.txt"
+	echo "Running Dig Scan..."
+	scan=`$DIG $HOST any > $REPORTNAME`
+	cat $REPORTNAME >> $FINALREPORT
+    fi
+}
+
+function helpMeMenu {
+    clear
+    echo "$NAME"
+    echo ""
+    echo "1. Run All Audits"
+    echo "2. NMap Ping Scan [ip/net/domain]"
+    echo "3. NMap Stealth Port Scan [ip/net/domain]"
+    echo "4. Nikto Web Vuln Scan [ip/domain]"
+    echo "5. Nessus Vuln Scan [ip/net/domain]"
+    echo "6. DNA ASP Vuln Scan [ip/domain]"
+    echo "7. GHBA RNDS Scan [ip/net]"
+    echo "8. WhoIs Scan [domain]"
+    echo "9. Dig Scan [domain]"
+    echo "   -ctrl-c to quit"
+    echo ""
+    echo "ip= xxx.xxx.xxx.xxx"
+    echo "net= xxx.xxx.xxx.xxx/xx"
+    echo "domain= mydomain.com"
+    echo ""
+    echo -n "Enter an Audit Choice: "
+    read MENUCHOICE
+    echo ""
+    echo -n "Enter the IP/Net-Block to scan [none]: "
+    read IPADDRESS
+    echo -n "Enter the Domain to scan [none]: "
+    read HOST
+    echo -n "Enter the email address to report to [none]: "
+    read EMAIL
+    echo -n "Enter the CRID of the server [none]: "
+    read CRID
+    echoVars
+    UNIXDATESTART=`date +"%s"`
+    
+    case $MENUCHOICE in
+	"1") 
+	     nmapPing
+	     ghbaScan
+	     whoisScan
+	     digScan
+             nmapStealth
+	     dnaScan
+             niktoScan
+             nessusScan
+             reporter
+	     echo -n "All Scans Finished. Press Enter. "
+	     read NULLKEY
+	     clear
+	     helpMeMenu
+	     ;;
+        "2") nmapPing
+	     reporter
+             echo -n "Ping Scan Finished. Press Enter. "
+             read NULLKEY
+             clear
+             helpMeMenu
+	;;
+        "3") nmapStealth
+             reporter
+             echo -n "Stealth Scan Finished. Press Enter. "
+             read NULLKEY
+             clear
+             helpMeMenu
+        ;;
+        "4") niktoScan
+             reporter
+             echo -n "Nikto Scan Finished. Press Enter. "
+             read NULLKEY
+             clear
+             helpMeMenu
+        ;;
+        "5") nessusScan
+             reporter
+             echo -n "Nessus Scan Finished. Press Enter. "
+             read NULLKEY
+             clear
+             helpMeMenu
+        ;;
+        "6") dnaScan
+             reporter
+             echo -n "DNA Scan Finished. Press Enter. "
+             read NULLKEY
+             clear
+             helpMeMenu
+        ;;
+        "7") ghbaScan
+             reporter
+             echo -n "GHBA Scan Finished. Press Enter. "
+             read NULLKEY
+             clear
+             helpMeMenu
+        ;;
+        "8") whoisScan
+             reporter
+             echo -n "WhoIS Scan Finished. Press Enter. "
+             read NULLKEY
+             clear
+             helpMeMenu
+        ;;
+        "9") digScan
+             reporter
+             echo -n "Dig Scan Finished. Press Enter. "
+             read NULLKEY
+             clear
+             helpMeMenu
+        ;;
+	"") echo ""
+	    echo -n "YOU DIDN'T CHOOSE AN AUDIT!!!!"
+	    read NULLKEY
+	    helpMeMenu
+	;;
+    esac
+}
+
+function echoVars {
+    echo ""
+    echo "#############################################################################"
+    echo "Scanning CRID: $CRID on IP/NET-BLOCK: $IPADDRESS for HOST: $HOST"
+    echo "Emailing Report to: $EMAIL"
+    echo "#############################################################################"
+    echo ""
+}
+
+#This is the money shot
+helpMeMenu
+
+#!/bin/bash
+OLDIFS=$IFS
+IFS=$'\n'
+tempsum=0
+totalmem=0
+for m in `ps -eo user,rss --sort user | sed -e 's/  */ /g' | awk -F'[ ]' {'print $0'}`; do
+    nu=`echo $m|cut -d" " -f1`
+    nm=`echo $m|cut -d" " -f2`
+    if [ "$nu" != "$ou" ] && [ $(echo "$nm"|grep -E "^[0-9]+$") ] 
+    then 
+        if [ "$tempsum" -ne 0 ]; then echo "Printing total mem for $ou: $tempsum"; fi
+        ou=$nu
+        tempsum=$nm
+        let "totalmem += $nm"
+    else 
+        let "tempsum += $nm" 
+        let "totalmem += $nm"
+    fi
+done
+echo "Total Memory in Use: $totalmem/$(free | grep Mem: | awk '{print $2}')"
+IFS=$OLDIFS

mysql-memory-report-storedproc.sql

+#####################################################################
+## NAME: memory_report_sp.sql
+## AUTHOR: Matt Reid
+## SITE: http://themattreid.com
+## DATE: 2012-09-02
+## LICENSE: GPL v3
+##
+## INSTALL METHODS: 
+##  a) install via linux shell
+##     $> mysql --user=root -p mysql < memory_report_sp.sql
+##  b) install via mysql command line
+##     mysql> use mysql; import memory_report_sp.sql
+##
+## USAGE:
+##  execute the stored procedure to generate the report
+##     mysql> use mysql; 
+##     mysql> call memory_report();
+##
+## EXAMPLE OUTPUT:
+##  [localhost mysql://root@localhost/mysql > call memory_report();
+##  +-----------------------------+----------+
+##  | VARIABLE                    | VALUE    |
+##  +-----------------------------+----------+
+##  | TOTAL_BUFFERS_GLOBAL        | 42.00 M  |
+##  | TOTAL_BUFFERS_PER_THREAD    | 2.72 M   |
+##  | MAX_CONNECTIONS_LIMIT       | 151      |
+##  | MAX_CONNECTIONS_USED        | 2        |
+##  | MAX_CONNECTION_USED_PERCENT | 1.32 %   |
+##  | TOTAL_MEMORY_LIMIT          | 452.53 M |
+##  | TOTAL_MEMORY_ACTIVE         | 47.44 M  |
+##  | TOTAL_MEMORY_ACTIVE_PERCENT | 10.48 %  |
+##  | HEAP_TABLE_LIMIT            | 16.00 M  |
+##  | TEMP_TABLE_LIMIT            | 16.00 M  |
+##  +-----------------------------+----------+
+##  10 rows in set (0.02 sec)
+#####################################################################
+
+DELIMITER $$
+DROP PROCEDURE IF EXISTS `memory_report` $$
+CREATE PROCEDURE `memory_report` ()
+BEGIN
+
+
+#####################################################################
+## Declare some variables
+#####################################################################
+DECLARE SUM_SGA BIGINT UNSIGNED;
+DECLARE SUM_PGA BIGINT UNSIGNED;
+DECLARE MAX_CONNECTIONS_LIMIT INT;
+DECLARE MAX_CONNECTIONS_USED INT;
+DECLARE CONNECTION_RATIO FLOAT;
+DECLARE TOTAL_HEAP BIGINT UNSIGNED;
+DECLARE TOTAL_TEMPTABLE BIGINT UNSIGNED;
+DECLARE k VARCHAR(255);
+DECLARE v BIGINT UNSIGNED;
+DECLARE TICK BOOL;
+
+DECLARE MEM_LIMIT BIGINT UNSIGNED;
+DECLARE MEM_USED BIGINT UNSIGNED;
+DECLARE MEM_PERC FLOAT;
+DECLARE MAX_CONNECTION_USED_PERCENT FLOAT;
+
+#####################################################################
+## Declare the queries
+#####################################################################
+DECLARE GLOBALS CURSOR FOR SELECT 
+	VARIABLE_NAME, VARIABLE_VALUE
+	FROM INFORMATION_SCHEMA.GLOBAL_VARIABLES
+	WHERE VARIABLE_NAME IN
+		('query_cache_size',
+		'key_buffer_size',
+		'innodb_buffer_pool_size',
+		'innodb_additional_mem_pool_size',
+		'innodb_log_buffer_size',
+		'read_buffer_size',
+		'read_rnd_buffer_size',
+		'sort_buffer_size',
+		'thread_stack',
+		'join_buffer_size',
+		'binlog_cache_size',
+		'max_connections',	
+		'max_heap_table_size',
+		'tmp_table_size') 
+	UNION
+	SELECT VARIABLE_NAME, VARIABLE_VALUE
+	FROM INFORMATION_SCHEMA.GLOBAL_STATUS
+	WHERE VARIABLE_NAME IN
+		('max_used_connections');
+
+
+DECLARE CONTINUE HANDLER FOR NOT FOUND SET TICK = 1;
+
+
+#####################################################################
+## Set default values
+#####################################################################
+SET SUM_SGA = 0;
+SET SUM_PGA = 0;
+SET MAX_CONNECTIONS_LIMIT = 0;
+SET MAX_CONNECTIONS_USED = 0;
+SET CONNECTION_RATIO = 0;
+SET TOTAL_HEAP = 0;
+SET TOTAL_TEMPTABLE = 0;
+
+
+#####################################################################
+## Query global variables
+#####################################################################
+SET TICK = 0;
+OPEN GLOBALS;
+looper:LOOP
+      FETCH GLOBALS INTO k,v;
+  IF TICK = 1 THEN
+    LEAVE looper;
+  END IF;
+
+    IF k in ('query_cache_size','key_buffer_size','innodb_buffer_pool_size','innodb_additional_mem_pool_size','innodb_log_buffer_size') 
+       THEN SET SUM_SGA = SUM_SGA + v;
+    ELSEIF k in ('read_buffer_size','read_rnd_buffer_size','sort_buffer_size','thread_stack','join_buffer_size','binlog_cache_size') 	
+       THEN SET SUM_PGA = SUM_PGA + v;
+    ELSEIF k in ('max_connections') THEN SET MAX_CONNECTIONS_LIMIT = v;
+    ELSEIF k in ('max_heap_table_size') THEN SET TOTAL_HEAP = v;
+    ELSEIF k in ('tmp_table_size','max_heap_table_size')
+     THEN SET TOTAL_TEMPTABLE = IF ((TOTAL_TEMPTABLE > v), TOTAL_TEMPTABLE, v);
+    ELSEIF k in ('max_used_connections') THEN SET MAX_CONNECTIONS_USED = v;
+
+    END IF;
+
+END LOOP;
+CLOSE GLOBALS;
+
+
+#####################################################################
+## Output report
+#####################################################################
+SET MEM_LIMIT = ROUND((SUM_SGA + (MAX_CONNECTIONS_LIMIT * SUM_PGA))/POW(1024,2),2); 
+SET MEM_USED = ROUND((SUM_SGA + (MAX_CONNECTIONS_USED * SUM_PGA))/POW(1024,2),2);
+SET MEM_PERC = ROUND((MEM_USED * 100)/MEM_LIMIT,2);
+SET MAX_CONNECTION_USED_PERCENT = ROUND((MAX_CONNECTIONS_USED * 100)/MAX_CONNECTIONS_LIMIT,2);
+
+SELECT "GLOBAL_BUFFERS_TOTAL" AS VARIABLE, CONCAT(ROUND(SUM_SGA/POW(1024,2),2),' M') AS VALUE UNION
+SELECT "THREAD_BUFFERS_TOTAL", CONCAT(ROUND((SUM_PGA * MAX_CONNECTIONS_LIMIT)/POW(1024,2),2),' M') UNION
+SELECT "THREAD_BUFFERS_EACH", CONCAT(ROUND(SUM_PGA/POW(1024,2),2),' M') UNION
+
+SELECT "MAX_CONNECTIONS_LIMIT", MAX_CONNECTIONS_LIMIT UNION
+SELECT "MAX_CONNECTIONS_USED", MAX_CONNECTIONS_USED UNION
+SELECT "MAX_CONNECTION_USED_PERCENT", CONCAT(MAX_CONNECTION_USED_PERCENT, ' %') UNION
+
+SELECT "MEMORY_UTILIZATION_LIMIT", CONCAT(MEM_LIMIT,' M') UNION
+SELECT "MEMORY_UTILIZATION_ACTIVE", CONCAT(MEM_USED,' M') UNION
+SELECT "MEMORY_UTILIZATION_RATIO", CONCAT(MEM_PERC,' %') UNION
+
+SELECT "HEAP_TABLE_LIMIT", CONCAT(ROUND(TOTAL_HEAP / POW(1024,2),2),' M') UNION
+SELECT "TEMP_TABLE_LIMIT", CONCAT(ROUND(TOTAL_TEMPTABLE / POW(1024,2),2),' M') ;
+
+END $$
+DELIMITER ;

mysql-rotate-logs.sh

+#!/bin/sh
+################################################################################
+## Kontrollkit
+## NAME: kt-rotate-logs.sh
+## DATE: 2008-10-01
+## AUTHOR: Matt Reid & Jim Wood
+## WEBSITE: http://kontrollsoft.com
+## EMAIL: themattreid@gmail.com
+## LICENSE: BSD http://www.opensource.org/licenses/bsd-license.php
+################################################################################
+## Copyright 2008 Matt Reid
+## All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+# 1. Redistributions of source code must retain the above copyright
+#    notice, this list of conditions and the following disclaimer.
+# 2. Redistributions in binary form must reproduce the above copyright
+#    notice, this list of conditions and the following disclaimer in the
+#    documentation and/or other materials provided with the distribution.
+# 3. The name of the author may not be used to endorse or promote products
+#    derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+##################################################################################
+#
+## WHAT THIS SCRIPT DOES #########################################################
+#rotates mysql general and slow logs on a periodic basis when run from crontab
+####
+#/etc/crontab entry
+# MySQL rotate logs
+#05 * * * * root /usr/local/bin/mysql_rotatelogs > /dev/null 2>&1
+####
+# SET OPTIONS HERE
+ROTATE_SLOW="1" # 0 for no rotation, 1 for yes
+ROTATE_GENERAL="1" # 0 for no rotation, 1 for yes
+MYUSER="root" #username
+MYPASS="nGEdcbrQlPkL" #password
+LOG_DIR="/var/lib/mysql" #location of mysql log files
+ROTATE_DIR="/home/mysql-backups/archive" #location to rotate files to
+GEN_LOG="mysql-gen.log" #general query log name
+SLOW_LOG="mysql-slow.log" #slow query log name
+#### DO NOT EDIT BELOW HERE ######
+##################################################################################
+export LOG_DIR ROTATE_DIR GEN_LOG SLOW_LOG DSTAMP MYUSER MYPASS
+DSTAMP=`date '+%d%m%G-%H%M%S'`
+
+# Zero the vars
+GEN_SIZE=0
+GEN_LIMIT=0
+SLOW_SIZE=0
+SLOW_LIMIT=0
+DONE_GEN=0
+DONE_SLOW=0
+
+# Rotate General log
+rotate_gen ()
+{
+    #echo "GEN Log is " ${GEN_SIZE}
+    mv ${LOG_DIR}/${GEN_LOG} ${ROTATE_DIR}/${GEN_LOG}.${DSTAMP}
+}
+
+# Rotate Slow log
+rotate_slow ()
+{
+    #echo "SLOW Log is " ${SLOW_SIZE}
+    mv ${LOG_DIR}/${SLOW_LOG} ${ROTATE_DIR}/${SLOW_LOG}.${DSTAMP}
+}
+
+start_func() {
+# Flush and compress accordingly
+    test -d ${ROTATE_DIR} || mkdir -p ${ROTATE_DIR}
+    if [ "$ROTATE_GENERAL" = "1" ]; then
+	GEN_SIZE=`ls -l ${LOG_DIR}/${GEN_LOG} | awk -F" " '{ print $5 }'`
+	GEN_LIMIT=500
+	#echo "GEN_SIZE=$GEN_SIZE"
+	#echo "GEN_LIMIT=$GEN_LIMIT"
+	if [ ${GEN_SIZE} -gt ${GEN_LIMIT} ]; then
+	    STATE_GEN="1"
+	    rotate_gen
+	fi
+    fi
+    if [ "$ROTATE_SLOW" = "1" ]; then
+	SLOW_SIZE=`ls -l ${LOG_DIR}/${SLOW_LOG} | awk -F" " '{ print $5 }'`
+	SLOW_LIMIT=1500
+        #echo "SLOW_SIZE=$SLOW_SIZE"
+        #echo "SLOW_LIMIT=$SLOW_LIMIT"
+	if [ ${SLOW_SIZE} -gt ${SLOW_LIMIT} ]; then
+	    STATE_SLOW="1"
+	    rotate_slow
+	fi
+    fi
+    
+    # Flush MySQL Logs
+    /usr/bin/mysqladmin --user="$MYUSER" --password="$MYPASS" flush-logs
+    
+    # Compress rotated logs
+   if [ "$STATE_GEN" = "1" ]; then
+       /bin/gzip ${ROTATE_DIR}/${GEN_LOG}.${DSTAMP}
+   fi
+   if [ "$STATE_SLOW" = "1" ]; then
+       /bin/gzip ${ROTATE_DIR}/${SLOW_LOG}.${DSTAMP}
+   fi
+}
+
+start_func

mysql_schema_iterator.sh

+#!/bin/sh
+HOST="localhost"
+USER="root"
+PASS="pass"
+
+DBS=`mysql -u$USER --password=$PASS --host=$HOST -s -e "show databases"`
+
+for each in $DBS; do 
+    DB=$each
+    if [ $DB = "Database" ]; then
+	echo ""	
+    else 
+	TABLE=`mysql -u$USER --password=$PASS --host=$HOST -s -e "show tables" $DB`	    
+	echo "$DB.$TABLE"
+    fi
+done
+#!/bin/sh
+#Matt Reid matthew@servepath.com / themattreid@gmail.com
+#10/10/05
+#simple script to interface with Ping and Nmap to support ping of subnets
+#$1 is the IP or Subnet, $2 is the ping -c amount
+
+helpMe() {
+	echo "Replacement for the Ping command. Uses NMap to support subnet ping scanning."
+	echo "Usage: ping [ip/subnet] [ping count]"
+	echo "location of Nmap: `which nmap`"
+	echo "location of Ping: `which ping`"
+}
+
+#check if second arg for ping count was given
+pingIp() {
+IP=$1
+#set COUNT=4 if $2 is not given
+COUNT=${2:-4}
+$PINGC -c $COUNT $IP
+}
+
+checkArg() {
+if [ -z "$1" ]; then #no IP/subnet given
+    helpMe
+else
+    if echo $1 | grep -q -v / ; then 
+	echo "#### SINGLE IP - NOT A SUBNET - USING PING ####"
+	pingIp $1 $2
+    else
+	echo "#### SUBNET - USING NMAP ####"
+        $NMAPC -sP $1
+    fi
+fi
+}
+
+#find locations of necessary commands
+PINGC=`which ping`
+NMAPC=`which nmap`
+#run the functions
+checkArg $1 $2
+-------------------------------------------------------------------------
+USEFUL ONE-LINE SCRIPTS FOR SED (Unix stream editor)        Dec. 29, 2005
+Compiled by Eric Pement - pemente[at]northpark[dot]edu        version 5.5
+
+Latest version of this file (in English) is usually at:
+   http://sed.sourceforge.net/sed1line.txt
+   http://www.pement.org/sed/sed1line.txt
+
+This file will also available in other languages:
+  Chinese     - http://sed.sourceforge.net/sed1line_zh-CN.html
+  Czech       - http://sed.sourceforge.net/sed1line_cz.html
+  Dutch       - http://sed.sourceforge.net/sed1line_nl.html
+  French      - http://sed.sourceforge.net/sed1line_fr.html
+  German      - http://sed.sourceforge.net/sed1line_de.html
+  Italian     - (pending)
+  Portuguese  - http://sed.sourceforge.net/sed1line_pt-BR.html
+  Spanish     - (pending)
+
+
+FILE SPACING:
+
+ # double space a file
+ sed G
+
+ # double space a file which already has blank lines in it. Output file
+ # should contain no more than one blank line between lines of text.
+ sed '/^$/d;G'
+
+ # triple space a file
+ sed 'G;G'
+
+ # undo double-spacing (assumes even-numbered lines are always blank)
+ sed 'n;d'
+
+ # insert a blank line above every line which matches "regex"
+ sed '/regex/{x;p;x;}'
+
+ # insert a blank line below every line which matches "regex"
+ sed '/regex/G'
+
+ # insert a blank line above and below every line which matches "regex"
+ sed '/regex/{x;p;x;G;}'
+
+NUMBERING:
+
+ # number each line of a file (simple left alignment). Using a tab (see
+ # note on '\t' at end of file) instead of space will preserve margins.
+ sed = filename | sed 'N;s/\n/\t/'
+
+ # number each line of a file (number on left, right-aligned)
+ sed = filename | sed 'N; s/^/     /; s/ *\(.\{6,\}\)\n/\1  /'
+
+ # number each line of file, but only print numbers if line is not blank
+ sed '/./=' filename | sed '/./N; s/\n/ /'
+
+ # count lines (emulates "wc -l")
+ sed -n '$='
+
+TEXT CONVERSION AND SUBSTITUTION:
+
+ # IN UNIX ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format.
+ sed 's/.$//'               # assumes that all lines end with CR/LF
+ sed 's/^M$//'              # in bash/tcsh, press Ctrl-V then Ctrl-M
+ sed 's/\x0D$//'            # works on ssed, gsed 3.02.80 or higher
+
+ # IN UNIX ENVIRONMENT: convert Unix newlines (LF) to DOS format.
+ sed "s/$/`echo -e \\\r`/"            # command line under ksh
+ sed 's/$'"/`echo \\\r`/"             # command line under bash
+ sed "s/$/`echo \\\r`/"               # command line under zsh
+ sed 's/$/\r/'                        # gsed 3.02.80 or higher
+
+ # IN DOS ENVIRONMENT: convert Unix newlines (LF) to DOS format.
+ sed "s/$//"                          # method 1
+ sed -n p                             # method 2
+
+ # IN DOS ENVIRONMENT: convert DOS newlines (CR/LF) to Unix format.
+ # Can only be done with UnxUtils sed, version 4.0.7 or higher. The
+ # UnxUtils version can be identified by the custom "--text" switch
+ # which appears when you use the "--help" switch. Otherwise, changing
+ # DOS newlines to Unix newlines cannot be done with sed in a DOS
+ # environment. Use "tr" instead.
+ sed "s/\r//" infile >outfile         # UnxUtils sed v4.0.7 or higher
+ tr -d \r <infile >outfile            # GNU tr version 1.22 or higher
+
+ # delete leading whitespace (spaces, tabs) from front of each line
+ # aligns all text flush left
+ sed 's/^[ \t]*//'                    # see note on '\t' at end of file
+
+ # delete trailing whitespace (spaces, tabs) from end of each line
+ sed 's/[ \t]*$//'                    # see note on '\t' at end of file
+
+ # delete BOTH leading and trailing whitespace from each line
+ sed 's/^[ \t]*//;s/[ \t]*$//'
+
+ # insert 5 blank spaces at beginning of each line (make page offset)
+ sed 's/^/     /'
+
+ # align all text flush right on a 79-column width
+ sed -e :a -e 's/^.\{1,78\}$/ &/;ta'  # set at 78 plus 1 space
+
+ # center all text in the middle of 79-column width. In method 1,
+ # spaces at the beginning of the line are significant, and trailing
+ # spaces are appended at the end of the line. In method 2, spaces at
+ # the beginning of the line are discarded in centering the line, and
+ # no trailing spaces appear at the end of lines.
+ sed  -e :a -e 's/^.\{1,77\}$/ & /;ta'                     # method 1
+ sed  -e :a -e 's/^.\{1,77\}$/ &/;ta' -e 's/\( *\)\1/\1/'  # method 2
+
+ # substitute (find and replace) "foo" with "bar" on each line
+ sed 's/foo/bar/'             # replaces only 1st instance in a line
+ sed 's/foo/bar/4'            # replaces only 4th instance in a line
+ sed 's/foo/bar/g'            # replaces ALL instances in a line
+ sed 's/\(.*\)foo\(.*foo\)/\1bar\2/' # replace the next-to-last case
+ sed 's/\(.*\)foo/\1bar/'            # replace only the last case
+
+ # substitute "foo" with "bar" ONLY for lines which contain "baz"
+ sed '/baz/s/foo/bar/g'
+
+ # substitute "foo" with "bar" EXCEPT for lines which contain "baz"
+ sed '/baz/!s/foo/bar/g'
+
+ # change "scarlet" or "ruby" or "puce" to "red"
+ sed 's/scarlet/red/g;s/ruby/red/g;s/puce/red/g'   # most seds
+ gsed 's/scarlet\|ruby\|puce/red/g'                # GNU sed only
+
+ # reverse order of lines (emulates "tac")
+ # bug/feature in HHsed v1.5 causes blank lines to be deleted
+ sed '1!G;h;$!d'               # method 1
+ sed -n '1!G;h;$p'             # method 2
+
+ # reverse each character on the line (emulates "rev")
+ sed '/\n/!G;s/\(.\)\(.*\n\)/&\2\1/;//D;s/.//'
+
+ # join pairs of lines side-by-side (like "paste")
+ sed '$!N;s/\n/ /'
+
+ # if a line ends with a backslash, append the next line to it
+ sed -e :a -e '/\\$/N; s/\\\n//; ta'
+
+ # if a line begins with an equal sign, append it to the previous line
+ # and replace the "=" with a single space
+ sed -e :a -e '$!N;s/\n=/ /;ta' -e 'P;D'
+
+ # add commas to numeric strings, changing "1234567" to "1,234,567"
+ gsed ':a;s/\B[0-9]\{3\}\>/,&/;ta'                     # GNU sed
+ sed -e :a -e 's/\(.*[0-9]\)\([0-9]\{3\}\)/\1,\2/;ta'  # other seds
+
+ # add commas to numbers with decimal points and minus signs (GNU sed)
+ gsed -r ':a;s/(^|[^0-9.])([0-9]+)([0-9]{3})/\1\2,\3/g;ta'
+
+ # add a blank line every 5 lines (after lines 5, 10, 15, 20, etc.)
+ gsed '0~5G'                  # GNU sed only
+ sed 'n;n;n;n;G;'             # other seds
+
+SELECTIVE PRINTING OF CERTAIN LINES:
+
+ # print first 10 lines of file (emulates behavior of "head")
+ sed 10q
+
+ # print first line of file (emulates "head -1")
+ sed q
+
+ # print the last 10 lines of a file (emulates "tail")
+ sed -e :a -e '$q;N;11,$D;ba'
+
+ # print the last 2 lines of a file (emulates "tail -2")
+ sed '$!N;$!D'
+
+ # print the last line of a file (emulates "tail -1")
+ sed '$!d'                    # method 1
+ sed -n '$p'                  # method 2
+
+ # print the next-to-the-last line of a file
+ sed -e '$!{h;d;}' -e x              # for 1-line files, print blank line
+ sed -e '1{$q;}' -e '$!{h;d;}' -e x  # for 1-line files, print the line
+ sed -e '1{$d;}' -e '$!{h;d;}' -e x  # for 1-line files, print nothing
+
+ # print only lines which match regular expression (emulates "grep")
+ sed -n '/regexp/p'           # method 1
+ sed '/regexp/!d'             # method 2
+
+ # print only lines which do NOT match regexp (emulates "grep -v")
+ sed -n '/regexp/!p'          # method 1, corresponds to above
+ sed '/regexp/d'              # method 2, simpler syntax
+
+ # print the line immediately before a regexp, but not the line
+ # containing the regexp
+ sed -n '/regexp/{g;1!p;};h'
+
+ # print the line immediately after a regexp, but not the line
+ # containing the regexp
+ sed -n '/regexp/{n;p;}'
+
+ # print 1 line of context before and after regexp, with line number
+ # indicating where the regexp occurred (similar to "grep -A1 -B1")
+ sed -n -e '/regexp/{=;x;1!p;g;$!N;p;D;}' -e h
+
+ # grep for AAA and BBB and CCC (in any order)
+ sed '/AAA/!d; /BBB/!d; /CCC/!d'
+
+ # grep for AAA and BBB and CCC (in that order)
+ sed '/AAA.*BBB.*CCC/!d'
+
+ # grep for AAA or BBB or CCC (emulates "egrep")
+ sed -e '/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d    # most seds
+ gsed '/AAA\|BBB\|CCC/!d'                        # GNU sed only
+
+ # print paragraph if it contains AAA (blank lines separate paragraphs)
+ # HHsed v1.5 must insert a 'G;' after 'x;' in the next 3 scripts below
+ sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;'
+
+ # print paragraph if it contains AAA and BBB and CCC (in any order)
+ sed -e '/./{H;$!d;}' -e 'x;/AAA/!d;/BBB/!d;/CCC/!d'
+
+ # print paragraph if it contains AAA or BBB or CCC
+ sed -e '/./{H;$!d;}' -e 'x;/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d
+ gsed '/./{H;$!d;};x;/AAA\|BBB\|CCC/b;d'         # GNU sed only
+
+ # print only lines of 65 characters or longer
+ sed -n '/^.\{65\}/p'
+
+ # print only lines of less than 65 characters
+ sed -n '/^.\{65\}/!p'        # method 1, corresponds to above
+ sed '/^.\{65\}/d'            # method 2, simpler syntax
+
+ # print section of file from regular expression to end of file
+ sed -n '/regexp/,$p'
+
+ # print section of file based on line numbers (lines 8-12, inclusive)
+ sed -n '8,12p'               # method 1
+ sed '8,12!d'                 # method 2
+
+ # print line number 52
+ sed -n '52p'                 # method 1
+ sed '52!d'                   # method 2
+ sed '52q;d'                  # method 3, efficient on large files
+
+ # beginning at line 3, print every 7th line
+ gsed -n '3~7p'               # GNU sed only
+ sed -n '3,${p;n;n;n;n;n;n;}' # other seds
+
+ # print section of file between two regular expressions (inclusive)
+ sed -n '/Iowa/,/Montana/p'             # case sensitive
+
+SELECTIVE DELETION OF CERTAIN LINES:
+
+ # print all of file EXCEPT section between 2 regular expressions
+ sed '/Iowa/,/Montana/d'
+
+ # delete duplicate, consecutive lines from a file (emulates "uniq").
+ # First line in a set of duplicate lines is kept, rest are deleted.
+ sed '$!N; /^\(.*\)\n\1$/!P; D'
+
+ # delete duplicate, nonconsecutive lines from a file. Beware not to
+ # overflow the buffer size of the hold space, or else use GNU sed.
+ sed -n 'G; s/\n/&&/; /^\([ -~]*\n\).*\n\1/d; s/\n//; h; P'
+
+ # delete all lines except duplicate lines (emulates "uniq -d").
+ sed '$!N; s/^\(.*\)\n\1$/\1/; t; D'
+
+ # delete the first 10 lines of a file
+ sed '1,10d'
+
+ # delete the last line of a file
+ sed '$d'
+
+ # delete the last 2 lines of a file
+ sed 'N;$!P;$!D;$d'
+
+ # delete the last 10 lines of a file
+ sed -e :a -e '$d;N;2,10ba' -e 'P;D'   # method 1
+ sed -n -e :a -e '1,10!{P;N;D;};N;ba'  # method 2
+
+ # delete every 8th line
+ gsed '0~8d'                           # GNU sed only
+ sed 'n;n;n;n;n;n;n;d;'                # other seds
+
+ # delete lines matching pattern
+ sed '/pattern/d'
+
+ # delete ALL blank lines from a file (same as "grep '.' ")
+ sed '/^$/d'                           # method 1
+ sed '/./!d'                           # method 2
+
+ # delete all CONSECUTIVE blank lines from file except the first; also
+ # deletes all blank lines from top and end of file (emulates "cat -s")
+ sed '/./,/^$/!d'          # method 1, allows 0 blanks at top, 1 at EOF
+ sed '/^$/N;/\n$/D'        # method 2, allows 1 blank at top, 0 at EOF
+
+ # delete all CONSECUTIVE blank lines from file except the first 2:
+ sed '/^$/N;/\n$/N;//D'
+
+ # delete all leading blank lines at top of file
+ sed '/./,$!d'
+
+ # delete all trailing blank lines at end of file
+ sed -e :a -e '/^\n*$/{$d;N;ba' -e '}'  # works on all seds
+ sed -e :a -e '/^\n*$/N;/\n$/ba'        # ditto, except for gsed 3.02.*
+
+ # delete the last line of each paragraph
+ sed -n '/^$/{p;h;};/./{x;/./p;}'
+
+SPECIAL APPLICATIONS:
+
+ # remove nroff overstrikes (char, backspace) from man pages. The 'echo'
+ # command may need an -e switch if you use Unix System V or bash shell.
+ sed "s/.`echo \\\b`//g"    # double quotes required for Unix environment
+ sed 's/.^H//g'             # in bash/tcsh, press Ctrl-V and then Ctrl-H
+ sed 's/.\x08//g'           # hex expression for sed 1.5, GNU sed, ssed
+
+ # get Usenet/e-mail message header
+ sed '/^$/q'                # deletes everything after first blank line
+
+ # get Usenet/e-mail message body
+ sed '1,/^$/d'              # deletes everything up to first blank line
+
+ # get Subject header, but remove initial "Subject: " portion
+ sed '/^Subject: */!d; s///;q'
+
+ # get return address header
+ sed '/^Reply-To:/q; /^From:/h; /./d;g;q'
+
+ # parse out the address proper. Pulls out the e-mail address by itself
+ # from the 1-line return address header (see preceding script)
+ sed 's/ *(.*)//; s/>.*//; s/.*[:<] *//'
+
+ # add a leading angle bracket and space to each line (quote a message)
+ sed 's/^/> /'
+
+ # delete leading angle bracket & space from each line (unquote a message)
+ sed 's/^> //'
+
+ # remove most HTML tags (accommodates multiple-line tags)
+ sed -e :a -e 's/<[^>]*>//g;/</N;//ba'
+
+ # extract multi-part uuencoded binaries, removing extraneous header
+ # info, so that only the uuencoded portion remains. Files passed to
+ # sed must be passed in the proper order. Version 1 can be entered
+ # from the command line; version 2 can be made into an executable
+ # Unix shell script. (Modified from a script by Rahul Dhesi.)
+ sed '/^end/,/^begin/d' file1 file2 ... fileX | uudecode   # vers. 1
+ sed '/^end/,/^begin/d' "$@" | uudecode                    # vers. 2
+
+ # sort paragraphs of file alphabetically. Paragraphs are separated by blank
+ # lines. GNU sed uses \v for vertical tab, or any unique char will do.
+ sed '/./{H;d;};x;s/\n/={NL}=/g' file | sort | sed '1s/={NL}=//;s/={NL}=/\n/g'
+ gsed '/./{H;d};x;y/\n/\v/' file | sort | sed '1s/\v//;y/\v/\n/'
+
+ # zip up each .TXT file individually, deleting the source file and
+ # setting the name of each .ZIP file to the basename of the .TXT file
+ # (under DOS: the "dir /b" switch returns bare filenames in all caps).
+ echo @echo off >zipup.bat
+ dir /b *.txt | sed "s/^\(.*\)\.TXT/pkzip -mo \1 \1.TXT/" >>zipup.bat
+
+TYPICAL USE: Sed takes one or more editing commands and applies all of
+them, in sequence, to each line of input. After all the commands have
+been applied to the first input line, that line is output and a second
+input line is taken for processing, and the cycle repeats. The
+preceding examples assume that input comes from the standard input
+device (i.e, the console, normally this will be piped input). One or
+more filenames can be appended to the command line if the input does
+not come from stdin. Output is sent to stdout (the screen). Thus:
+
+ cat filename | sed '10q'        # uses piped input
+ sed '10q' filename              # same effect, avoids a useless "cat"
+ sed '10q' filename > newfile    # redirects output to disk
+
+For additional syntax instructions, including the way to apply editing
+commands from a disk file instead of the command line, consult "sed &
+awk, 2nd Edition," by Dale Dougherty and Arnold Robbins (O'Reilly,
+1997; http://www.ora.com), "UNIX Text Processing," by Dale Dougherty
+and Tim O'Reilly (Hayden Books, 1987) or the tutorials by Mike Arst
+distributed in U-SEDIT2.ZIP (many sites). To fully exploit the power
+of sed, one must understand "regular expressions." For this, see
+"Mastering Regular Expressions" by Jeffrey Friedl (O'Reilly, 1997).
+The manual ("man") pages on Unix systems may be helpful (try "man
+sed", "man regexp", or the subsection on regular expressions in "man
+ed"), but man pages are notoriously difficult. They are not written to
+teach sed use or regexps to first-time users, but as a reference text
+for those already acquainted with these tools.
+
+QUOTING SYNTAX: The preceding examples use single quotes ('...')
+instead of double quotes ("...") to enclose editing commands, since
+sed is typically used on a Unix platform. Single quotes prevent the
+Unix shell from intrepreting the dollar sign ($) and backquotes
+(`...`), which are expanded by the shell if they are enclosed in
+double quotes. Users of the "csh" shell and derivatives will also need
+to quote the exclamation mark (!) with the backslash (i.e., \!) to
+properly run the examples listed above, even within single quotes.
+Versions of sed written for DOS invariably require double quotes
+("...") instead of single quotes to enclose editing commands.
+
+USE OF '\t' IN SED SCRIPTS: For clarity in documentation, we have used
+the expression '\t' to indicate a tab character (0x09) in the scripts.
+However, most versions of sed do not recognize the '\t' abbreviation,
+so when typing these scripts from the command line, you should press
+the TAB key instead. '\t' is supported as a regular expression
+metacharacter in awk, perl, and HHsed, sedmod, and GNU sed v3.02.80.
+
+VERSIONS OF SED: Versions of sed do differ, and some slight syntax
+variation is to be expected. In particular, most do not support the
+use of labels (:name) or branch instructions (b,t) within editing
+commands, except at the end of those commands. We have used the syntax
+which will be portable to most users of sed, even though the popular
+GNU versions of sed allow a more succinct syntax. When the reader sees
+a fairly long command such as this:
+
+   sed -e '/AAA/b' -e '/BBB/b' -e '/CCC/b' -e d
+
+it is heartening to know that GNU sed will let you reduce it to:
+
+   sed '/AAA/b;/BBB/b;/CCC/b;d'      # or even
+   sed '/AAA\|BBB\|CCC/b;d'
+
+In addition, remember that while many versions of sed accept a command
+like "/one/ s/RE1/RE2/", some do NOT allow "/one/! s/RE1/RE2/", which
+contains space before the 's'. Omit the space when typing the command.
+
+OPTIMIZING FOR SPEED: If execution speed needs to be increased (due to
+large input files or slow processors or hard disks), substitution will
+be executed more quickly if the "find" expression is specified before
+giving the "s/.../.../" instruction. Thus:
+
+   sed 's/foo/bar/g' filename         # standard replace command
+   sed '/foo/ s/foo/bar/g' filename   # executes more quickly
+   sed '/foo/ s//bar/g' filename      # shorthand sed syntax
+
+On line selection or deletion in which you only need to output lines
+from the first part of the file, a "quit" command (q) in the script
+will drastically reduce processing time for large files. Thus:
+
+   sed -n '45,50p' filename           # print line nos. 45-50 of a file
+   sed -n '51q;45,50p' filename       # same, but executes much faster
+
+If you have any additional scripts to contribute or if you find errors
+in this document, please send e-mail to the compiler. Indicate the
+version of sed you used, the operating system it was compiled for, and
+the nature of the problem. To qualify as a one-liner, the command line
+must be 65 characters or less. Various scripts in this file have been
+written or contributed by:
+
+ Al Aab                   # founder of "seders" list
+ Edgar Allen              # various
+ Yiorgos Adamopoulos      # various
+ Dale Dougherty           # author of "sed & awk"
+ Carlos Duarte            # author of "do it with sed"
+ Eric Pement              # author of this document
+ Ken Pizzini              # author of GNU sed v3.02
+ S.G. Ravenhall           # great de-html script
+ Greg Ubben               # many contributions & much help
+-------------------------------------------------------------------------

svn_commit_wrapper.sh

+#!/bin/sh
+HERE=`pwd`
+VER=`svnversion |awk -F: {'print $2'}|sed 's/M//g'|sed 's/S//g'`
+if [ "$VER" = "" ]; then
+    VER=`svnversion |sed 's/M//g'|sed 's/S//g'`
+fi
+NVER=`expr $VER + 1`
+echo $NVER > $HERE/version.txt
+echo "updated verion.txt to revision: $NVER"
+svn commit
+#!/bin/bash
+## NAME: TunnelMaker
+## PURPOSE: Creates multi-hop SSH tunnels for forwarding data+connections
+## AUTHOR: Matt Reid
+## DATE: 2012-05-30
+## VERSION: 1.0.2-jf
+##sample: echo "ssh -v -L $localport:localhost:$remotehost1port $remotehost1 ssh -v -L $remotehost1port:localhost:$remotehost2port -N $remotehost2 ... repeat"
+
+echo "------------------->"
+echo "-->Tunnel-->Maker-->"
+echo "-->version: 1.0.2-jf"
+echo "-->themattreid.com"
+echo "------------------->" 
+
+## Get sequence value
+echo -n "How many hops are we making [#remote servers]: "
+read hops
+
+## Check user, set initial port, root user can set N<1024 port value
+user=`whoami`
+notice=' [>1024]' 
+if [ "$user" = "root" ]; then notice=''; fi 
+
+## Initialize some vars
+c=1                 #session value counter
+n=''                #session value for notice
+final=''            #end result string for tunnel command
+localport='2222'    #localhost port default
+destport='22'     #destination port default
+let hops=hops+1     #increment hops for iteration in loop
+
+## Build connection strings
+while [  $c -lt $hops ]; do
+    echo ""    
+    echo -n "Host[or IP] for hop#[$c]: "; read host
+    echo -n "Localhost port for $host$notice: "; read localport    
+    echo -n "Destination port for $host$notice: "; read destport    
+
+    if [ "$localport" = '' ]; then echo "no port selected. exiting." exit 1; fi
+    if [ "$destport" = '' ]; then echo "no port selected. exiting." exit 1; fi
+    if [ $c -gt 1 ]; then n="-N "; fi #added to suppress remote login
+
+    string="ssh -v -L $localport:localhost:$destport $n$host "
+    final="$final $string"
+    let c=c+1
+
+done
+
+echo ""
+echo "You can initiate your tunnels via command: \"$final\""
+echo "Shall I start the tunnel now? [y,N]: "; read choice
+if [ "$choice" = "Y" ] || [ "$choice" = "y" ]; then `$final`; else exit 0; fi
+
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.