nix, shell, perl, php, mysql and mac os x tips and tricks

Friday, November 20, 2009

show number of messages in postfix queue

postqueue -p | tail -n 1 | cut -d' ' -f5

Tuesday, November 10, 2009

Shell script to determine if an IP is pingable

#!/bin/bash

# default host
HOST="10.0.0.1"

# check if there's a host as an argument
if [ $# -eq 1 ]
 then
 HOST=$1
fi

count=$(/sbin/ping -c 1 -t 2 $HOST | /usr/bin/grep 'received' | /sw/bin/awk -F',' '{ print $2 }' | /sw/bin/awk '{ print $1 }') ;
echo "$count"

Grab the load average as a usable number

uptime | awk -F "load average: " '{ print $2 }' | cut -d, -f1
another way:
uptime | awk '{print $8}' | cut -d "," -f 1
yet another:
uptime | sed -e "s/^.*[a-z]: //; s/,.*//"

Wednesday, November 4, 2009

Vacuum the SQLite database to speed up Firefox on os x

Go Tools -> Error Console and paste the line below in the "Code" field, enter and wait. It actually makes a noticeable difference.
Components.classes["@mozilla.org/browser/nav-history-service;1"].getService(Components.interfaces.nsPIPlacesDatabase).DBConnection.executeSimpleSQL("VACUUM");