Skip to content

Instantly share code, notes, and snippets.

@metalrufflez
metalrufflez / count_conns.sh
Last active August 29, 2015 14:00
Count all TCP connections for a given port
function count_conns() {
if [[ $# -eq 0 ]]; then
echo "Usage: $FUNCNAME <port>"
return
fi
ss -t -n "src :$1" | awk '{print $5}' | sed 1d | sort | cut -d: -f1 | uniq -c | sort -k1,1nr -t. -k2,2n -k3,3n -k4,4n -k5,5n
}

Keybase proof

I hereby claim:

  • I am metalrufflez on github.
  • I am caiocorrea (https://keybase.io/caiocorrea) on keybase.
  • I have a public key whose fingerprint is 1508 220E 626F 81C3 E688 E06B 78A1 17C5 BD0A 8EB4

To claim this, I am signing this object:

@metalrufflez
metalrufflez / create_db.sls
Last active August 29, 2015 14:07
Create Database Users
include:
- salt.mysql
{% for db, db_details in pillar.get('db_config', {}).items() %}
{{ db }}_database:
mysql_database.present:
- name: {{ db }}
{% for user, user_details in db_details['users'].items() %}
{{ user }}_user_in_{{ db }}:
@metalrufflez
metalrufflez / ora11bkphourly.sh
Created November 21, 2011 14:17
Dump and Oracle 11g (set it to run houly on cron)
#!/bin/bash
export ORACLE_HOME="/path/to/oracle/home"
export ORACLE_SID=SID
DB_BKPDIR="/path/to/backup/dir"
#EXPORT DA BASE DE DADOS
echo "Dumping Database"
#${ORACLE_HOME}/bin/exp \"/ as sysdba\" file=$DB_BKPDIR/bkp_hourly.dmp log=$DB_BKPDIR/bkp_hourly.log buffer=3000000 compress=y full=y
@metalrufflez
metalrufflez / ora11bkp.sh
Created November 21, 2011 14:16
Full backup an Oracle 11g database (remember to alter the target date to keep the backups)
#!/bin/bash
export ORACLE_HOME="/path/to/oracle/home"
export ORACLE_SID=SID
DB_BKPDIR="/path/to/backup/directory"
DMPFILE="bkp_$(date +%y%m%d).dmp"
TARFILE="bkp_$(date +%y%m%d).tar.bz2"
LOGFILE="bkp_$(date +%y%m%d).log"
@metalrufflez
metalrufflez / monitordhl.sh
Created November 21, 2011 13:54
Script to parse and mail DHL tracking updates
#!/bin/bash
URL='http://www.dhl.com/content/g0/en/express/tracking.shtml?brand=DHL&AWB=<INSERT_TRACKING_CODE_HERE>%0D%0A'
BULK="$(curl -s "$URL" | egrep -A1 -m1 '<td class=".*" style="width: 5% ;text-align:left">.+</td>' | egrep -o '>.+<' | sed 's/[><]//g')"
CODE="$(echo $BULK | cut -d " " -f1)"
CTLFILE=/root/ctlfile
if [ "$CODE" -ne "$(cat $CTLFILE)" ]; then
echo $CODE > $CTLFILE
mail -s "DHL Update" <INSERT_YOUR_EMAIL_HERE> < <(echo $BULK)
@metalrufflez
metalrufflez / migratevm.sh
Created November 21, 2011 14:05
Migrate Xen 5.* VMs using an external disk on the newhost
#!/bin/bash
# Uncomment the lines below to print the commands instead of executing them
# DEBUG refers to exporting from external dom0
# DEBUG2 refers to importing the vm to local dom0
#DEBUG="echo"
#DEBUG2="echo"
# You HAVE to inform at lease vm and host or else, usage in your face
if [ "$#" -lt 2 ]; then
@metalrufflez
metalrufflez / mlogrotate.sh
Created November 21, 2011 14:08
manual logrotate (remember to adapt the FILE_DATE to your case)
#!/bin/bash
FILE_DIR="/path/to/dir/"
DATE_TARGET=$(date +"%Y%m%d" --date='2 days ago')
for FILE_NAME in $(ls $FILE_DIR/*.log)
do
FILE_DATE=$(echo $FILE_NAME | cut -d"-" -f2 | cut -d"." -f1)
if [ "$FILE_DATE" -le "$DATE_TARGET" ]; then
rm -f $FILE_NAME
@metalrufflez
metalrufflez / ora10bkphourly.sh
Created November 21, 2011 14:14
Dump an Oracle 10g (set it to run houly on cron)
#!/bin/bash
export ORACLE_HOME="/path/to/oracle/home"
export ORACLE_SID=SID
DB_BKPDIR="/path/to/backup/directory"
#EXPORT DA BASE DE DADOS
echo "Dumping Database"
${ORACLE_HOME}/bin/exp \"/ as sysdba\" file=$DB_BKPDIR/bkp_hourly.dmp log=$DB_BKPDIR/bkp_hourly.log buffer=3000000 compress=y full=y
@metalrufflez
metalrufflez / zmparseusers.sh
Last active September 28, 2015 10:18
Create a file to use with the zmcreateusers
#!/bin/bash
# zmparseusers
# Create a formatted list to be used with zmcreateusers
# AUTHOR: Caio Correa
# Provided a file with a list of names like
#
# John Doe
# Lucy Doe