NFS shares keep on dropping in leopard?

Had a problem recently with nfs shares disconnecting all the time, much to my annoyance.

Turns out that it’s due to the .DS_Store files on the server, so a quick

find / -name [.]DS_Store -exec rm -f {} \;</pre>
on the server sorted that out.

Now to stop leopard from making them, on the client machine run:
<pre>defaults write com.apple.desktopservices DSDontWriteNetworkStores true

this should hold true for samba mounts too.

the DS_Store file is apparently a hangover from OS9. It holds information relating to the remembered view of the folder, so by deleting them all, and stopping new ones you are forcing the default view on all the networked folders, no biggie

Habey launched mini itx with 6 SATA, 2Gb ethernet

just came up ion linuxdevices link

Remotely enable terminal servces on a win5x or 6x box

  • connect remote registry
  • browse to HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server.
  • change fDenyTSConnections to 0
  • reboot remote machine with shutdown -r -t 00 -m \\[computername]
  • connect: mstsc /{admin or console} /v:[computername]

Postfix, postgrey, and targrey. How’s that for a boring title, yay!

YupYup,

installed postgrey & targrey today:

wget http://postgrey.schweikert.ch/pub/postgrey-1.32.tar.gz
tar xvfz postgrey-1.32.tar.gz
cd postgrey-1.32
wget http://k2net.hakuba.jp/pub/targrey-0.31-postgrey-1.32.patch
cp ./postgrey postgrey.orig
patch < targrey-0.31-postgrey-1.32.patch
cp ./postgrey /usr/sbin/
cp ./postgrey_whitelist_clients /etc/postfix
cp ./postgrey_whitelist_recipients /etc/postfix
groupadd mail
useradd -g mail -d /home/postgrey -m -s /bin/false postgrey
mkdir /var/run/postgrey/
chown -R postgrey:mail /var/run/postgrey/
mkdir /var/spool/postfix/postgrey
chown postgrey:mail /var/spool/postfix/postgrey -R

Now create an init file:

vi /etc/init.d/postgrey

and put this in it:

#!/bin/bash
#
# Init file for postgrey server daemon
#
# chkconfig: 2345 79 30
# description: postgrey server daemon
#
# processname: postgrey
case "$1" in
start)
# Start Postgrey
/usr/sbin/postgrey --inet=127.0.0.1:60000 --daemonize --pidfile=/var/run/postgrey/postgrey.pid --whitelist-clients=/etc/postfix/postgrey_whitelist_clients --whitelist-recipients=/etc/postfix/postgrey_whitelist_recipients --greylist-action=451 --delay=420 --max-age=40 --lookup-by-subnet --auto-whitelist-clients=10 --user=postgrey --group=mail
;;
stop)
# Stop Postgrey
killall /usr/sbin/postgrey
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
;;
esac

make it executable:

chown 754 /etc/init.d/postgrey

and tell your system to start it when the system starts
Debian:

update-rc.d postgrey defaults

Redhat:

chkconfig --add postgrey

now tell postfix to use it, edit /etc/postfix/main.cf and add

check_policy_service   inet:60000

to the end of the smtpd_recipient_restrictions and smtpd_data_restrictions statements, so they look something like this:

smtpd_recipient_restrictions =
    permit_mynetworks
    permit_sasl_authenticated
    reject_unauth_destination
    ...(whitelist and other filter)
    check_client_access regexp:$config_directory/permit_client_nots25r
    check_policy_service   inet:60000
    ...
    permit

smtpd_data_restrictions =
    permit_mynetworks
    permit_sasl_authenticated
    ...(whitelist)
    check_client_access regexp:$config_directory/permit_client_nots25r
    check_policy_service   inet:60000
    permit

And that’s your lot.

Spamassasin sa-learn automatic from exchange mailbox

I needed a script to auto bayes learn spam, there were a couple out there, but all old, and none of them did imaps, which is what exchange needs. So herre you go:

#!/usr/bin/perl
#
# 20081006
# from flipsidereality.com
#
# script to pull spam and ham from exchange by imaps, push it through sa-learn, and then delete it from the exchange server.

use Mail::IMAPClient;
use IO::Socket::SSL;

my $debug=0;
my $salearn;
# Define our server and credentials here
my $username = 'XXXXXX';
my $password = 'xxxxxxxx';
my $server = 'imaps.mail.server';
my $spam_folder = 'bySPAM';
my $ham_folder = 'byFALSE_POSITIVE';
my $amavis_user = 'amavis'; # User to run sa-learn in the context of,

# Open an SSL session to the IMAP server
# Handles the SSL setup, and gives us back a socket
my $ssl=new IO::Socket::SSL("$server:imaps");
die ("Error connecting - $@") unless defined $ssl;
$ssl->autoflush(1);

# Initialise the IMAP object
# Annoyingly, when giving it a Socket, it won't do the initial IMAP
# welcome stuff, so we have to do that ourselves a little later on
my $imap=Mail::IMAPClient->new(
	Socket => $ssl,
	Debug => $debug,
	User => $username,
	Password => $password,
	Peek => 0
);

# Tell Mail::IMAPClient we're connected
$imap->State(Mail::IMAPClient::Connected);

# Get the IMAP Server to the point of accepting a login prompt
# Basically, we skip over the welcome messages until at the OK stage
my ($code, $output) = ("","");
until ( $code ) {
	$output = $imap->_read_line or return undef;
	for my $o (@$output) {
		$imap->_debug("Connect: Received this from readline: ".join("/",@$o)."\n");
		$imap->_record($imap->Count,$o);        # $o is a ref
		next unless $o->[Mail::IMAPClient::TYPE] eq "OUTPUT";
		($code) = $o->[Mail::IMAPClient::DATA] =~ /^\*\s+(OK|BAD|NO)/i  ;
	}
}
# Did we get an OK welcome back?
if ($code =~ /BYE|NO /) {
	$imap->State("Unconnected");
	die "IMAP server disconnected";
}

# Now, have Mail::IMAPClient send the login for us
$imap->login;

if (!defined($imap)) { die "IMAP Login Failed"; }

# If debugging, print out the total counts for each mailbox
if ($debug) {
  my $spamcount = $imap->message_count($spam_folder);
  print ">>> ", $spamcount, " $spam_folder to process <<<\n";

  my $nonspamcount = $imap->message_count($ham_folder);
  print ">>> ", $nonspamcount, " $ham_folder to process <<<\n" if $debug;
}

# Process the spam mailbox
$imap->select($spam_folder);
my @msgs = $imap->search("ALL");
for (my $i=0;$i <= $#msgs; $i++)
{
  # I put it into a file for processing, doing it into a perl var & piping through sa-learn just didn't seem to work
  $imap->message_to_file("/tmp/salearn",$msgs[$i]);

  # execute sa-learn w/data
  if ($debug) { $salearn = `su $amavis_user -c '/usr/bin/sa-learn -D --no-sync --showdots --spam /tmp/salearn'`; }
  else { $salearn = `su $amavis_user -c '/usr/bin/sa-learn --no-sync --showdots --spam /tmp/salearn'`; }
  print "-------\nSpam: ",$salearn,"\n-------\n" if $debug;

  # delete processed message
  $imap->delete_message($msgs[$i]);
  unlink("/tmp/salearn");
}
$imap->expunge();
$imap->close();

# Process the not-spam mailbox
$imap->select($ham_folder);
my @msgs = $imap->search("ALL");
for (my $i=0;$i <= $#msgs; $i++)
{
  $imap->message_to_file("/tmp/salearn",$msgs[$i]);
  # execute sa-learn w/data
  if ($debug) { $salearn = `su $amavis_user -c '/usr/bin/sa-learn -D --no-sync --showdots --ham /tmp/salearn'`; }
  else { $salearn = `su $amavis_user -c '/usr/bin/sa-learn --no-sync --showdots --ham /tmp/salearn'`; }
  print "-------\nNotSpam: ",$salearn,"\n-------\n" if $debug;

  # delete processed message
  $imap->delete_message($msgs[$i]);
  unlink("/tmp/salearn");
}
$imap->expunge();
$imap->close();
$imap->logout();

# integrate learned stuff, but only if there was something to integrate.
if ("$salearn" =~ m/Learned/gi )
{
	my $sarebuild = `su $amavis_user -c '/usr/bin/sa-learn --sync'`;
	print "-------\nSync: ",$sarebuild,"\n-------\n" if $debug;
}

ffmpeg cheat sheet

ffmpeg is a multiplatform, open-source library for video and audio files. I have compiled 19 useful and amazing commands covering almost all needs: video conversion, sound extraction, encoding file for iPod or PSP, and more.

Getting infos from a video file
ffmpeg -i video.avi
Turn X images to a video sequence
ffmpeg -f image2 -i image%d.jpg video.mpg

This command will transform all the images from the current directory (named image1.jpg, image2.jpg, etc…) to a video file named video.mpg.

Turn a video to X images
ffmpeg -i video.mpg image%d.jpg

This command will generate the files named image1.jpg, image2.jpg, …

The following image formats are also availables : PGM, PPM, PAM, PGMYUV, JPEG, GIF, PNG, TIFF, SGI.

Encode a video sequence for the iPpod/iPhone
ffmpeg -i source_video.avi input -acodec aac -ab 128kb -vcodec mpeg4 -b 1200kb -mbd 2 -flags +4mv+trell -aic 2 -cmp 2 -subcmp 2 -s 320x180 -title X final_video.mp4

Explanations :

  • Source : source_video.avi
  • Audio codec : aac
  • Audio bitrate : 128kb/s
  • Video codec : mpeg4
  • Video bitrate : 1200kb/s
  • Video size : 320px par 180px
  • Generated video : final_video.mp4
Encode video for the PSP
ffmpeg -i source_video.avi -b 300 -s 320x240 -vcodec xvid -ab 32 -ar 24000 -acodec aac final_video.mp4

Explanations :

  • Source : source_video.avi
  • Audio codec : aac
  • Audio bitrate : 32kb/s
  • Video codec : xvid
  • Video bitrate : 1200kb/s
  • Video size : 320px par 180px
  • Generated video : final_video.mp4
Extracting sound from a video, and save it as Mp3
ffmpeg -i source_video.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 sound.mp3

Explanations :

  • Source video : source_video.avi
  • Audio bitrate : 192kb/s
  • output format : mp3
  • Generated sound : sound.mp3
Convert a wav file to Mp3
ffmpeg -i son_origine.avi -vn -ar 44100 -ac 2 -ab 192 -f mp3 son_final.mp3
Convert .avi video to .mpg
ffmpeg -i video_origine.avi video_finale.mpg
Convert .mpg to .avi
ffmpeg -i video_origine.mpg video_finale.avi
Convert .avi to animated gif(uncompressed)
ffmpeg -i video_origine.avi gif_anime.gif
Mix a video with a sound file
ffmpeg -i son.wav -i video_origine.avi video_finale.mpg
Convert .avi to .flv
ffmpeg -i video_origine.avi -ab 56 -ar 44100 -b 200 -r 15 -s 320x240 -f flv video_finale.flv
Convert .avi to dv
ffmpeg -i video_origine.avi -s pal -r pal -aspect 4:3 -ar 48000 -ac 2 video_finale.dv

Or:

ffmpeg -i video_origine.avi -target pal-dv video_finale.dv
Convert .avi to mpeg for dvd players
ffmpeg -i source_video.avi -target pal-dvd -ps 2000000000 -aspect 16:9 finale_video.mpeg

Explanations :

  • target pal-dvd : Output format
  • ps 2000000000 maximum size for the output file, in bits (here, 2 Gb)
  • aspect 16:9 : Widescreen
Compress .avi to divx
ffmpeg -i video_origine.avi -s 320x240 -vcodec msmpeg4v2 video_finale.avi
Compress Ogg Theora to Mpeg dvd
ffmpeg -i film_sortie_cinelerra.ogm -s 720x576 -vcodec mpeg2video -acodec mp3 film_terminée.mpg
Compress .avi to SVCD mpeg2

NTSC format:

ffmpeg -i video_origine.avi -target ntsc-svcd video_finale.mpg

PAL format:

ffmpeg -i video_origine.avi -target pal-svcd video_finale.mpg
Compress .avi to VCD mpeg2

NTSC format:

ffmpeg -i video_origine.avi -target ntsc-vcd video_finale.mpg

PAL format:

ffmpeg -i video_origine.avi -target pal-vcd video_finale.mpg
Multi-pass encoding with ffmpeg
ffmpeg -i fichierentree -pass 2 -passlogfile ffmpeg2pass fichiersortie-2

This was shamelessly stolen from http://www.catswhocode.com/blog/os/19-ffmpeg-commands-for-all-needs-824

Aspell PSPELL win32 fastcgi problems

So i had fun with aspell on a win2003 IIS PHP eAccelerator fastCGI PSPELL Aspell setup today.

I was getting a 500 error from fastcgi. phpinfo() showed that pspell was loaded correctly. After pushing a test script through php.exe, and getting an error telling me that a file in the aspell data folder was in the wrong format, i tried DOS2UNIX ing the files in the progra~1\aspell\data folder and all was good!

Screen and the delete key - .screenrc

After a bit of poking around the interwebs i came across this little gem for getting screen to behave a bit better with the delete key.
Put this in your ~/.screenrc

termcapinfo xterm-color kD=\E[3~

the best thing is that you don’t even have to restart the screen to get it, just reattach.

Recursive unrar unzip perl script

It’s a bit hacky, but it works.

#!/usr/bin/perl
use File::Find;
use File::Spec;

if (@ARGV[0] eq '')
{
	print "useage: $0 foldername\n";
}
else
{
	print "Exctacting for folder ". $ARGV[0] ."\n";
	find ( \&extract_dir , @ARGV[0]);
	print (++$n,": $_\n") foreach (@elist) ;
}

exit;

sub extract_dir
{
next if -d $_;
next if /^\./;
my $ff = $File::Find::name;

	# deal with RAR files
	unrar($_,$ff);
	#deal with ZIP files
	if ($ff =~ /\.zip$/i )
	{
		print "unzip $ff";
		system ('unzip','-qq', "$_");
		if ($? != 0)
		{
			push (@elist, $ff);
		}
		else
		{
			print "\nrm -f $ff\n";
			system ('rm', '-f', $_);
		}
	}
}

sub unrar
# takes filename, full filename
{
	if ($_[0] =~ /\.rar$/i)
	{
		if ($_[0] =~ /\.part[0-9]+?\.rar$/i)
		{
			if ($_[0] =~ /\.part[0]+?1\.rar$/i)
			{
				print "unrar x $_[1] \n";
				system ('unrar','x','-y','-inul', "$_[0]");
				if ($? != 0)
				{
					push (@elist, "$_[1]");
				}
				else
				{
					my $todel = $_[0];
					$todel =~ s/\.part[0]+?1\.rar$/\.part*\.rar/g ;
					print "find ./ -name \"$todel\" -exec rm {} \\\;\n";
					system ("find ./ -name \"$todel\" -exec rm {} \\\;");
				}
			}
		}
		else
		{
			print "unrar x $_[1] \n";
			system ('unrar','x','-y','-inul', "$_[0]");
			if ($? != 0)
			{
				push (@elist, "$_[1]");
			}
			else
			{
				my $todel = $_[0];
				$todel =~ s/\.rar$/\.r*/g ;
				print "find ./ -name \"$todel\" -exec rm {} \\\;\n";
				system ("find ./ -name \"$todel\" -exec rm {} \\\;");
			}
		}
	}
}

Automate a Remote Login Using SSH-Agent

When it comes to remote logins, SSH is a wonderful tool. Not only is it
secure, it supports public/private key logins. Depending on public and
private keys mean even if someone gets your password, without your
private key it won’t do them any good (and vice versa).

see full article here