Posts categorized under: tech

MySQL Backup Script

#!/bin/bash

user='root'
pass='r00t'
date=$(date +%Y.%m.%d)
backuproot='/var/backups/mysql'

# echo and exit
function die {
    echo "$1"
    exit 1
}

# dump per database
function per_db {
    for db in $(mysql -u ${user} -p${pass} -Bse "show databases"); do
        [ ${db} = "information_schema" ] && continue
        [ ${db} = "performance_schema" ] && continue
        echo ${db}
        mysqldump …

Discovering the Seagate Central

NMAP Scan

ryant@spitfire:~$ nmap 192.168.1.11

Starting Nmap 6.00 ( http://nmap.org ) at 2013-06-29 13:17 SAST
Nmap scan report for 192.168.1.11
Host is up (0.0098s latency).
Not shown: 990 closed ports
PORT     STATE SERVICE
21/tcp   open  ftp
22/tcp   open …

Expect the Unexpected

Problem

Need to automate an rsync to a fileserver and, unfortunately, required to authenticate using a password.

Solution

Use expect...

#!/usr/bin/expect

set timeout 20
set password [lindex $argv 0]

spawn rsync -av --no-p --no-g  /media/ryant/My\ Book/Photo/ user@10.10.10.12:/Data/Public/Photos/

expect …

Persistence With SQLite

The Problem-ette

I needed to keep track of up until where in a database table I had already queried. Later queries needed to draw data from that point onwards. For example if I've done the query select id, name, surname from table where id > 255623 and it yielded results with …

Do They Fit?

Do you want to know if the MP3s in that folder will fit on a CD?

No problem.

#!/usr/bin/env python

import audioread
import sys

try:
    files = sys.argv[1:]
except:
    print('Usage: %s <files/glob>' % (sys.argv[0],))
    sys.exit()

total_length = 0.0
for file in files:
    f …

Commandline Completion for Fabric

To get a list of functions in a Fabric file you use fab --list. I use Fabric frequently so I thought I'd save myself some time by using bash completion to render fab --list obsolete.

Being a learn-from-example type of person I immediately consulted Google for some precedence. After a …