NukeAll – for OSX

nukeall finds and removes (recursevely) the specified file(s) in the current folder.
Example:
nukeall .DS_Store
nukeall *.tmp
nukeall .*

You can also pass the -trashes option which will search and empty. Trashes folders which is useful on file servers.

Version 1.0 can be downloaded by clicking here

Check Apple RAIDs and email when there is a problem

This script can be used in a cron which runs every 5 or 10 minutes and will email as soon as it detects an issue with an Apple RAID.
I am working on an Apple XServe RAID checker, but this one will handle internal drive bay RAIDs.

#!/usr/bin/env python

import os
import string
import smtplib

from socket import gethostname

smtpserver = 'localhost'
smtpfrom = gethostname() + '@localhost'
smtpto = ['##EMAIL_OF_RECIPIENT##']

raidstatus = os.popen('/usr/sbin/diskutil listRaid')
status = raidstatus.read()
raidstatus.close()
if status.find('Degraded') > -1:
     smtpsubject = 'WARNING - Raid degraded on ' + gethostname()
     smtp = smtplib.SMTP(smtpserver)
     message = """\
From: %s
To: %s
Subject: %s

%s
""" % (smtpfrom, ", ".join(smtpto), smtpsubject, status)
     smtp.sendmail(smtpfrom, smtpto, message)
     smtp.quit()

Check OSX partitions and email results

I wrote a small Python script which gets a list of partitions and checks each one to make sure the partition is okay, and for the script to email the results.

#!/usr/bin/env python

import os
import string
import smtplib

from socket import gethostname

smtpserver = 'localhost'
smtpfrom = gethostname() + '@localhost'
smtpto = ['##recipient email##']

driveshandle = os.popen('/bin/df -h | grep disk')
drives = driveshandle.read()
driveshandle.close()
drives = drives.split('\n')

for drive in drives:

     diskinfo = ''
     if drive.find('dev') > -1:
          partition = drive.split(' ')
          print 'Drive ' +partition[0]
          fsck = os.popen('/sbin/fsck_hfs -fy ' + partition[0])
          diskinfo = fsck.read()
          fsck.close()
          smtpsubject = 'File System Checks for ' + gethostname() + ', drive ' + drive
          smtp = smtplib.SMTP(smtpserver)
          message = """\
From: %s
To: %s
Subject: %s

%s
""" % (smtpfrom, ", ".join(smtpto), smtpsubject, diskinfo)
          smtp.sendmail(smtpfrom, smtpto, message)
          smtp.quit()

print 'completed'

OSX Command Line Goodies

You can take a screenshot by command:

screencapture -C ~/screen.png

This will save a screenshot into the user’s home folder.

You can get system information:

/usr/sbin/system_profiler SPHardwareDataType

Which would show something like this:
Hardware:

Hardware Overview:

Model Name: iMac
Model Identifier: iMac8,1
Processor Name: Intel Core 2 Duo
Processor Speed: 2.66 GHz
Number Of Processors: 1
Total Number Of Cores: 2
L2 Cache: 6 MB
Memory: 4 GB
Bus Speed: 1.07 GHz
Boot ROM Version: IM81.00C1.B00
SMC Version (system): 1.29f1
Serial Number (system): VM906KT5ZE3
Hardware UUID: FB5DEAE0-DAB6-56DD-A62B-0F38C384654A

Speaking- You can make the computer speak by commandline:

say -v Albert "Hello world"

Albert can be replaced with any of the following:

Agnes,Albert,BadNews,Bahh,Bells,Boing,Bruce,Bubbles,Cellos,Deranged,Fred,GoodNews,Hysterical,Junior,Kathy,Organ,Princess,Ralph,Trinoids,Vicki,Victoria,Whisper,Zarvox

Automatic checking of IMAP subfolders in Thunderbird

Open up the preferences dialog (either Tools -> Preferences or Edit -> Preferences), and click Advanced -> General -> Config Editor.
In the filter box type ‘mail.check’ and double click on mail.check_all_imap_folders_for_new.

That should do it..

The Dreadnought Framework

A friend of mine and I are working on a pretty impressive project which will hopefully fill a niche in the IT market.
Its a pretty impressive amount of work, but we are both up for a challenge, and the chance to sink a few beers on a project meeting will be a necessity.

One major milestone has been completed – the Dreadnought framework. Its basis is two files – index.php and _dreadnought.php. All heavy duty code is held in the dreadnought kernel – accessable through $dreadnought. Its very very simple. No access control, basic MySQL support but has a promising future.

I am developing a ‘blogging’ module into it, and hopefully will move this site from wordpress into Dreadnought in the not too distant future.

The one thing I really love about the way I have designed dreadnought is that the templating system could not be easier. You have a html file and just add the tag <DREADNOUGHT_CONTENT /> and the code does the rest.
I’m hoping to release the framework as open source soonish, but not until some more work has gone into it, including some rudimentary pre-flight checking of modules – ie to prevent a module from killing the framework’s kernel.

Mounting samba permanently

A nice quick and easy one..

Add the following into /etc/fstab, replacing the parts with stars with your information.

//**SERVER**/**SHARE** /mnt/**MOUNTPOINT** smbfs rw,user,username=**USER**,password=**PASS** 0 0

make sure the location /mnt/**MOUNTPOINT** exists, chmodded correctly (eg 666) and then just mount it with:

mount /mnt/**MOUNTPOINT**

Blocking tor through iptables

I keep a database of tor hosts which gets updated quite often, and I have written a script in python which downloads the list and updates iptables so that they are all blocked.

It is recommended that the script gets added to cron so that the machines iptables keep up to date.

This script is ideal for schools and businesses to prevent people from circumventing content filtering, and also useful for servers to prevent abuse from ‘anonymous’ people who use tor for hacking for denial of service.

The script can be found here (http://www.andydixon.com/blocktor.py) and requires python (tested on v2.6)

Multiple VLANs on 1 network port with Ubuntu / Debian

If you have a network with multiple VLANs and you want to be able to connect on more than one, you can set up virtual nics, one for each vlan.

To do this, you need to install the vlan package:
sudo apt-get -y install vlan

You then need to edit your /etc/network/interfaces to add the additional nics. For each vlan you wish to access, add the following lines, replacing information where necessary:

auto vlan5
iface vlan5 inet static
address 10.5.1.2
netmask 255.255.255.0
network 10.5.0.0
broadcast 10.5.255.255
gateway 10.5.0.1
mtu 1500
vlan_raw_device eth0

Once saved, you can just give your machine a quick reboot and all will be peachy.

Clearing MAILER-DAEMONS from Mail Queue

This little gem will certainly help get rid of pending bounce messages resulting from spam hitting your mail server:

mailq | tail -n +2 | grep -v ‘^ *(’ | awk ‘BEGIN { RS = “” }{ if ($7 == “MAILER-DAEMON” ) print $1 }’ | tr -d ‘*!’ | postsuper -d -

You cant really get simpler than this…