Re-Order Photos Using Bash

By , 12 November 2010

Here's a script I used to use to renumber the files in a directory according to their modification date.

#!/bin/sh

# Renames the files in the current directory to a 4 digit number
# which is their position in the directory multiplied by 10.
# This script is meant to help sort photos in your albums.
#
# Specify a starting number on the command line if you want to start
# at another number other than zero.
#
# If a second number is specified, this step value is used. Otherwise
# a step value of 1 is used
#

c=${1:-0}
s=${2:-1}

for i in `ls -t .`; do
    newname=`printf "%03d" $c`.`echo ${i:${#i}-3} | tr 'A-Z' 'a-z'`
    mv "$i" $newname
    c=`expr $c + $s`
done

No comments yet, be the first to comment!

Copy Files and Ignore Cyclic Redundancy Check Errors on Windows

By , 11 October 2010

Today I had the unfortunate pleasure of copying some data on a Windows machine. Windows File Explorer (or File Manager or Explorer or whatever they call it these days) has a hissy fit if any of the files cannot be read or has a CRC Cyclic Redundancy Check Error. It then helpfully bails out on the entire process.

Fortunately I discovered you can still use the xcopy command line utility with the /c switch to ignore errors in Windows. I solved my problem with the follow command.

xcopy /c /s d:\*.* e:\incoming

The /s is for recursion, and don't forget it's *.* in Windows, not just *

4 comments, post a comment!

Exim Autoreply Example (Exim4)

By , 10 October 2010

Here is some example Exim configuration for email autoreply where the email accounts and response text are kept in a postgresql database. First add a new router to the routers section like this one:

#
# Autoreply router which may pass messages to the autoreply transport.
# Unseen must be used to ensure the message is also delivered by passing
# it to the next router.
#
virtual_autoreply:
  driver = accept
  transport = autoreply
  unseen
  condition = ${lookup pgsql{SELECT 1 FROM email_accounts a \
	    WHERE a.localpart = '${quote_pgsql:$local_part}' AND \
	          a.domain = '${quote_pgsql:$domain}' AND \
                  a.autoreply = true}}

And in the transports section add the following.

#
# Autoreply transport. The entire autoreply email needs to built from 
# scratch.
#
autoreply:
  driver = autoreply
  to = ${reply_address}
  from = ${local_part}@${domain}
  subject = Re: $h_subject:
  text = ${lookup pgsql{SELECT autoMessage FROM email_accounts a \
	    WHERE a.localpart = '${quote_pgsql:$local_part}' AND \
	          a.domain = '${quote_pgsql:$domain}' AND \
                  a.autoreply = true}}

Read more...

No comments yet, be the first to comment!

Monitoring the JVM with SNMP + MRTG

By , 10 April 2009

Some time ago I blogged about monitoring the JVM with SNMP and OpenNMS. Here is an alternative method using the more lightweight MRTG which makes graphs such as the one below.

First you need to enable SNMP in your jvm by adding -Dcom.sun.management.config.file=snmp.properties to your java command line. You can do this for tomcat by adding it to CATALINA_OPTS in your startup script. Next, you need to create that properties file properly. The following example configures the daemon to listen on all interfaces on port 1161. The ACL is disabled so you keep your security configuration in your firewall instead.

com.sun.management.snmp.interface=0.0.0.0
com.sun.management.snmp.port=1161
com.sun.management.snmp.acl=false

Read more...

No comments yet, be the first to comment!

Netbeans 6.5 + Ubuntu 8.10 LAF Bug

By , 9 December 2008

This is how Netbeans 6.5 looked out of the box on Ubuntu 8.10 for me. The line spacing is screwed up.

The problem was Ubuntu had installed openjdk-6-jdk for me, but Netbeans must have only been tested with sun-java6-jdk. To fix this fire up your terminal and type:

$ sudo apt-get install sun-java6-jdk
$ sudo rm /usr/lib/jvm/default-java
$ sudo ln -s /usr/lib/jvm/java-6-sun-1.6.0.10/ /usr/lib/jvm/default-java

5 comments, post a comment!

Setting Your SVN Root with svn+ssh

By , 20 August 2008

Accessing your subversion repo via ssh is pretty nifty because you don't have to set up a special server or auth methods. The only problem is that out of the box, you are going to have to use the full path to your subversion root in the URLs. i.e. something like:

svn+ssh://svn.example.com/var/local/subversion/myproject

If you prefer to use a URL something like

svn+ssh://svn.example.com/myproject

you need to pass the -r option to svnserve when it is executed on the server. To do this, I usually replace the svnserve binary with a shell script that wraps the original program:

#!/bin/sh
/usr/bin/svnserve-real -r /var/local/subversion $*

Where svnserve-real is the orginal binary. The only problem with this method is that 'apt-get upgrade' likes to reinstall the binary. Perhaps somebody else has a better trick?

No comments yet, be the first to comment!

Handy Linux Commands

By , 31 July 2008

Images

Resize images:

$ mogrify -resize 50% *

Replace/attach image colour profile:

$ mogrify -profile ~/etc/argb.icc *

Lossless jpeg rotation based on EXIF data:

$ exifautotran *

Set the modification date of a photo based on EXIF data:

$ jhead -ft *

Audio

Fix Canon WAV files:

$ ffmpeg -acodec copy -i file.wav file2.wav

Video

Capture from video in (ffmpeg):

$ ffmpeg -ac 2 -ar 48000 -f oss -i /dev/dsp -s 720x576 -r 25 -f video4linux2 -i /dev/video0 -y -ac 1 -ab 192k -qscale 4 out.avi

Capture from video in (mencode):

$ mencoder tv:// -tv driver=v4l2:width=720:height=576:normid=4:input=0:fps=25:forceaudio:adevice=/dev/dsp:audiorate=48000 -oac mp3lame -lameopts br=224:mode=3 -ovc lavc -lavcopts vcodec=mpeg4:vqscale=4 -endpos 1:05:00 -o out.avi

Convert mjpeg to mpeg4:

$ ffmpeg -i file.avi -r 27 -qscale 6 -ab 128K -vcodec mpeg4 file.b.avi

Convert directory of mjpegs to mpeg2 and retain creation dates:

$ for i in *.avi; do ffmpeg -i $i -r 27 -ab 128K -sameq -vcodec mpeg2video ${i:0:${#i}-4}.mpg; touch -r $i ${i:0:${#i}-4}.mpg; done;

Convert ogg vorbis to flash video (requires mp3 support):

$ ffmpeg -i file.ogv -sameq file.flv

Filesystem

Loop over a list of files which contain spaces:

$ ls -1 | while read x; do echo $x; done

Convert absolute symlinks to relative ones (must be run twice):

$ symlinks -c -s .
$ symlinks -c -s .

Sync home dir with external hard drive:

$ rsync --delete --exclude ".*" --exclude Bureau --exclude tmp \
        -av /home/roger/ /media/disk

Convert DOS text file to UNIX:

$ apt-get install tofrodos
$ dos2unix {file}

Web

Download a website for offline reading:

$ wget -E -p -r -l inf -np -k http://www.example.com

Programming

Edit a log message:

$ svn propedit svn:log svn+ssh://svn.ninthavenue.com.au/blah -r11 --revprop

Import an upstream release (e.g. fckeditor):

~/fckeditor $ svn import svn+ssh://svn.ninthavenue.com.au/apps/fckeditor/tags/2.6.0

Merge custom changes into new upstream release:

~ $ svn co svn+ssh://svn.ninthavenue.com.au/apps/fckeditor/branches/2.6.0-webcore fckeditor
~ $ cd fckeditor
~/fckeditor $ svn merge svn+ssh://svn.ninthavenue.com.au/apps/fckeditor/tags/2.5.1 svn+ssh://svn.ninthavenue.com.au/apps/fckeditor/branches/2.5.1-ninthavenue

Install / add a jar file into maven:


mvn install:install-file -Dfile=jboss-el-2.0.1.jar -DartifactId=jboss-el -DgroupId=org.jboss.el -Dverion=2.0.1 -Dpackaging=jar

Bash

While loop:

#!/bin/sh
i=0
while [ x -lt 5 ]
do
        # do something
        i=`expr $i + 1`
done

 

No comments yet, be the first to comment!

Spampot test results

By , 14 June 2008

You read a lot online about how spammers are 'harvesting the Internet' by collecting email addresses off the web. People have come up with all sorts of methods to obfuscate their email address. So I thought I would give them a bit of a test out. I created some dummy email accounts and posted them on this site each using a different method of obfuscation. The variations used plain old mailto links, tinyurl redirects, escaping with unicode, inserting invisible tags in the address with display:none and using images. The addresses have now been online for several months so I thought I'd release the results of this monumental experiment. Here they are:

  • Plain old mailto link: 2 spams

That's where I stopped. Spammers don't harvest email addresses off the web. Writing crawlers to do it is too hard and uses too many resources. How many pages is it worth parsing to find just one email address? My guess is that their most productive sources are mailing lists, newsgroups and databases traded amongst themselves.

Mythbusted. Totally.

1 comment, post a comment!

Windows vs Linux

By , 16 April 2008

So I lie in bed, but sleep doesn't come. There's a little ideas man in my head streaming ceaseless chatter. "What's the point in even trying to sleep?" I ask myself, he just doesn't shut up. Then there's this frog in the neighbour's pond who does a remarkable imitation of somebody playing ping-pong against the wall. It doesn't shut up either - at least not until 4 or 5am. So I do the only sensible thing, and get up and log onto my blog.

Tonight I'm going to share with you a little bit of fun I had installing a new operating system on my desktop. Its called Windows XP and I'm told its fairly cutting edge. Apparently you can send emails and surf the Internet with it. Wow, cool!

Read more...

2 comments, post a comment!

How To Enable Native POSIX Threads on Debian Sarge

By , 4 April 2008

Ja, okej, so Sarge is getting a bit ancient but in the 3 years we've been running our server we've only had to reboot once to install a new kernel, so I'm not in a big hurry to upgrade. I did notice today though, while assessing the performance of the server, that our Java app server is spawning one process per thread. And here I was thinking that Java supported native kernel threads. Well, actually it does. My surprise was that, until fairly recently, it was Linux that didn't support kernel threads.

We were using the LinuxThreads library which creates user threads mapped to Linux processes with a shared memory space. The latest way to do threading is with the Native POSIX Thread Library (NPTL) which creates real kernel lightweight processes (LWPs). It needed Linux 2.6 which we had, but despite reading reports of people using it on Sarge, I couldn't find any articles explaining how to switch from LinuxThreads to NPTL.

So... I thought I'd better write one. It's not too hard:

Read more...

No comments yet, be the first to comment!

< Prev1 2 3 Next >