Skip to content

Instantly share code, notes, and snippets.

@jalexandre0
jalexandre0 / iptracker.sh
Last active December 17, 2015 13:49
Ip tracker when you can't use dyndns
#!/bin/bash
IP=$(curl -s ifconfig.me)
LAST_IP=$(cat /tmp/myip )
if [ "$IP" = "$LAST_IP" ]
then exit 0
else echo $IP > /tmp/myip ; echo $IP | mail -s "Valid IP for host XPTO" [email protected]
fi
@jalexandre0
jalexandre0 / check_internet.py
Last active December 16, 2015 20:00
###WIP### Check internet and change default routes if three sites are down.
#!/usr/bin/env python
import urllib2
import subprocess
import commands
debug = 1
def open_url(url):
try:
@jalexandre0
jalexandre0 / zabbix.housekeeping.sh
Created April 24, 2013 19:05
Housekeeping for postgresql and zabbix. I'm still using this after zabbix 2.0, and still working.
#Setting atual date
echo $(date +%d/%m/%Y-%H:%M)
#One year and month ago in Unix Timestamp
ONE_YEAR_AGO=$(expr `date +%s` - 31536000)
ONE_MONTH_AGO=$(expr `date +%s` - 2678400)
#Queries for one month ago
MONTH_TABLES="history history_uint history_str history_text history_log"
for table in $MONTH_TABLES
@jalexandre0
jalexandre0 / zabbix.blockdevices.discovery.pl
Last active December 16, 2015 15:19
Perl quick and dirty to get blockdevices. Used only in zabbix low level discovery. Its ugly, and works for me and... oh, wait, its perl. :D
#!/usr/bin/perl
$first = 1;
print "{\n";
print "\t\"data\":[\n\n";
#Need fix here. Proc Partitions to rescue
for (`/usr/bin/iostat -d 1 1 | grep -v Device | grep -v Linux| awk '{print \$1}' | sed '/^\$/d' `)
{
chomp $_ ;
print "\t,\n" if not $first;
$first = 0;
@jalexandre0
jalexandre0 / filecounter.py
Last active December 16, 2015 15:09
File counter to use when your run low of inodes and your system has only one partition. It is ugly, unpolished, unfinished and works perfectly for me ;)
#!/usr/bin/env python
import os
import sys
root_dir = str(sys.argv[1])
total = 0
def look_dirs(root_dir):
dir_list = []