Random Code


Jessie exim4 spf madness

Here's a strange thing. Seems like spf-tools-perl in jessie have some strange bugs. I never noticed, but after the update from wheezy SPF silently stopped working and the log was spammed with Warning: Unexpected error in SPF check. I traced this down to the invocation of /usr/bin/spfquery.mail-spf-perl which would abort with an error: unresolvable name: localhost at /usr/share/perl5/Mail/SPF/Server.pm line 225

The solution to all this madness, /etc/resolv.conf had an entry nameserver localhost. Changing that to 127.0.0.1 made the perl script and SPF checking work again. /etc/hosts does list 127.0.0.1 localhost, no idea why this broke.


Advertisement


Split a large directory into smaller chunks

I wanted to archive a 130GB directory containing various files to bluray discs. As bluray burning seems to be "highly experimental" under Linux, no GUI program I wanted to install could write to such a disc. On the command line it works with dvd+rw-tools which wants a subdirectory with contents that gets written to disc.

The code below takes an input directory 'basedir' and hardlinks its content into smaller directories under 'targetdir' with a maximum size of 'volumesize'.

#!/usr/bin/python # burns with: growisofs -udf -iso-level 3 -allow-limited-size -Z /dev/sr0 vol1/ import os basedir = '/media/Blackbox/More_Stuff/Software' targetdir = '/media/Blackbox/More_Stuff/Software-bkp' volumesize = 48440016896 # Size from dvd+rw-mediainfo print 'Creating hard-linked directory structure from\n%s\nto\n%s\nwith a volume size of %d bytes\n' % (basedir, targetdir, volumesize) def createroot(root): # print 'createroot on path %s' % root if not os.path.exists(root): os.makedirs(root) def makelink(relname): src = '%s/%s' % (basedir, relname) target = '%s/%s' % (volume_dir, relname) # print 'Linking %s -> %s\n' % (src, target) try: os.link(src, target) except OSError as error: print 'File probably not readable for us: %s' % src size = 0 vol = 1 volume_dir = '%s/vol%d' % (targetdir, vol) os.makedirs(volume_dir) for root, dirs, files in os.walk(basedir): for name in files: fname = os.path.join(root, name) fsize = os.path.getsize(fname) relname = os.path.relpath(fname, basedir) if (size + fsize) > volumesize: print 'Volume %d: %s bytes.' % (vol, size) # New volume vol += 1 size = fsize volume_dir = '%s/vol%d' % (targetdir, vol) os.makedirs(volume_dir) else: size += fsize newroot = os.path.dirname(os.path.join(volume_dir, relname)) createroot(newroot) makelink(relname) print 'Volume %d: %s bytes.' % (vol, size)

Index: 1