Simple mail server report

Here is a small script I wrote a few minutes ago. It gather some informations from the local machine and send them by email to the administrator (me). I plays nice with a @weekly rule in Cron.

It is easily customizable without further explanation. However, I think some enhancements should be added (multiple recipients, generic information addition etc.)

#!/bin/bash

# Configuration
SUBJECT="Server repport of `date +%m.%d.%y`"
EMAIL="root@domain.tld"
MSG="/tmp/weekreport"
touch $MSG

# Uptime
echo "Uptime" >> $MSG
echo "`uptime`" >> $MSG
echo "" >> $MSG

# Disk usage
echo "Disk usage" >> $MSG
echo "==========" >> $MSG
echo "" >> $MSG
echo "`df -h`" >> $MSG
echo "" >> $MSG

# Lighty status
echo "Lighttpd" >> $MSG
echo "========" >> $MSG
echo "`/usr/local/etc/rc.d/lighttpd status`" >> $MSG
echo "" >> $MSG

/usr/bin/mail -s "$SUBJECT" "$EMAIL" < $MSG
rm $MSG
Posted in None at January 21st, 2010. Comments.

About Apple’s Magic Mouse

In short: wow!

I recognize my not really inventive attitude, but I think there is no better summarize about my feelings.

The Apple Magic Mouse

Look

Well, just by itself, the mouse is really beautiful. I admit it would not be worse with a soft white light coming from the Apple logo, or from the sides of the mouse, but I think it looks really nice on my black desk. Furthermore its bright tactile surface reflects as a mirror does which makes the mouse “pop”.

Feel

My dear old PC mouse

My dear old PC mouse

My Apple computer is a Macbook Pro (of de 5th family I think. It looks like theses ones and costs me 1200 €), so it has a built-in mutltitouch trackpad which works very well. However, I missed my dear old PC mouse. You know, there is something really different between a trackpad and a mouse : the depth. The Magic mouse is really nice from this point of view: it allies the power of the multitouch technology and, with its subtle curves, the presence of a classic computer mouse.

First approach

There is nothing easier than connecting this mouse with your OS X based computer. Just power on the mouse (with a little brushed button like the power on/off on iPod Nano). If Bluetooth is enabled on your computer, a window should pop up, print you some messages, and disappear. That’s it. The mouse is running on your Mac. It’s a bit strange at first, but I got used to its smooth surface blazingly fast.

Get ready to ride

Since the mouse is available to sale, you can read everywhere that you must use MagicPrefs. That’s why I downloaded it to custom my mouse gestures. This tool is really nice (I don’t understand why Apple doesn’t provide such a software with Snow Leopard). But it has one major drawback: it doesn’t support tab (⇥) composed keyboard shortcuts. I wanted to use them for my Firefox (with ⌃⇧⇥ and ⌃⇥ to switch between opened tabs). After digging, let’s say, 2″40 seconds with Google, I found BetterTouchTool, a software similar to MagicPrefs but which is far more flexible (and it works for touchpads too). So I dropped MagicPrefs and installed BTT. Well, I can say I’ve never felt so relaxed with a computer (except when I switch from PHP to Python, but…).

[BetterTouchTool screenshot]

BetterTouchTool

Conclusion

To put it in a nutshell, I highly recommend you this mouse. Unless you are a narrow-minded conservative fundamentalist of keyboard as the only real interface with a computer, the Magic Mouse is really pleasant and easy to use. A nice purchase in my humble opinion.

Posted in None at January 21st, 2010. Comments.

Quicksort C++ implementation

Hello. I just had to implement a quicksort algorithm version in C++ for an exercise. Here is what I’ve done:

The code on friendpaste.com

#include <iostream>
#include <vector>

using namespace std;

void swap(int &a, int &b)
{
    int temp;
    a = b;
    b = temp;
}

int split_array(vector<int>& array, int pivot, int start_index, int end_index)
{
    int left_boundary = start_index;
    int right_boundary = end_index;

    while (left_boundary < right_boundary) {

        while (pivot < array[right_boundary] && right_boundary > left_boundary) {
            right_boundary--;
        }

        swap(array[left_boundary], array[right_boundary]);

        while (pivot >= array[left_boundary] && left_boundary < right_boundary) {
            left_boundary++;
        }

        swap(array[right_boundary], array[left_boundary]);
    }

    return left_boundary;
}

void quicksort(vector<int>& array, int start_index, int end_index)
{
    int pivot = array[start_index];
    int split_point;

    if (end_index > start_index) {
        split_point = split_array(array, pivot, start_index, end_index);
        array[split_point] = pivot;
        quicksort(array, start_index, split_point-1);
        quicksort(array, split_point+1, end_index);
    }
}
Posted in None at January 19th, 2010. Comments.

Time Machine, FreeBSD and AFP are on a little boat

Okay, I just had set up a backup system from a MacBookPro (let’s say, the client) to a FreeBSD-powered server (quite boringly, the server). I chose Time Machine because of it’s nice and polished interface and its deep integration with OSX. After a lot of (too much?) tries and spent time, I chose the AFP for the protocol between the two machines. I decided to write this post because there are plenty of outdated posts on the web concerning this setup, and I didn’t manage to hit my goal with them. So my post relates a way which works for me.

On the FreeBSD server

AFP service

The AFP protocol is provided by NetATalk, a free AFP implementation. Let’s install it with the ports tree:

cd /usr/ports/net/netatalk/ && make install clean

Add it to your configuration: add the following to /etc/rc.conf:

netatalk_enable="YES"
afpd_enable="YES"

Define an obscure setting in /usr/local/etc/afpd.conf:

"Time Machine" -uamlist uams_dhx2.so

Add your Time Machine share into /usr/local/etc/AppleVolumes.default (edit to make it fits your needs):

/storage/timemachine/    "Time Machine" allow:thomas

Finally start the service:

/usr/local/etc/rc.d/netatalk start

Howl (optional)

Howl is a free implementation of the Apple’s Bonjour protocol. It’s used to spread hostnames and shares on your network. You don’t really need it, but I think it’s smarter to use it.

Install by the ports tree:

cd /usr/ports/net/howl/ && make install clean

Add to the configuration (/etc/rc.conf):

mdnsresponder_enable="YES"
mdnsresponder_flags="-f /usr/local/etc/mDNSResponder.conf"

Create the configuration file /usr/local/etc/mDNSResponder.conf and fill it:

"Home Time Machine Server"     _afpovertcp._tcp     local.     548

Start the service:

/usr/local/etc/rc.d/mdnsresponder start

Needed steps on the client

Unsupported Network Volumes

By default, Time Machine only allows you to use an AirPort-based system if you want to backup your data throught your network. So we need to ask it politely to enable the support for every network drive. Grab your terminal and type:

defaults write com.apple.systempreferences TMShowUnsupportedNetworkVolumes 1

The sparsebundle image

(source of this part: http://jakub.fedyczak.net/post/28)

Since filesystem provided by FreeBSD is not quite compatible with Time Machine, you have to create your own file system image. Use Disk Utility to create image:

  • Save As: MachineNameMacAddress MachineName as read from “System Preferences / Sharing / Computer Name field”. MacAddress has to be ethernet address of en0 – as displayed in ifconfig en0 result in ehternet line – without colons. For example: jf010203040506. Always use ethernet interface. Wireless interface won’t work.
  • Name: Time Machine
  • Size: Custom – greater than your HD size (in fact, it’s the amount of disk space you want to allow to your backups)
  • Format: I use Mac OS Extended (Journaled) but I’m not sure which one is the best.
  • Partitions: Single partition – Apple partition map
  • Image format: sparse bundle disk image

Resulting file should have .sparsebundle extension. Copy it to your remote FreeBSD drive and you’re done.

Posted in None at January 11th, 2010. Comments.