A chronological documentation test project, nothing serious, really!

24 Sep 2012 Rotate and rename images according to their EXIF info

This is my short script to rotate and rename image files accoring to date captured based on their EXIF info.
You need jhead and exiv2 to run this. These two programs are also available in Windows and only require you to make small changes to work there as well.

#!/bin/bash -x
echo Rotating JPEG file(s)
jhead -ft -autorot D*.JPG

echo Rename(ing) file(s)
exiv2 -r '%Y%m%d-%H%M_:basename:' rename $(ls D*)

The files are then named like this (YYYYMMDD-HHDD_OriginalFileName.extension)


This script has been tested on Nikon D80 and D7000 image files.

Tags: , , , , , ,

Posted by

02 Aug 2012 Backup of Zimbra MailBox using zmmailbox

This is a short script I use to backup the Zimbra mailbox content for my users.
This has been used on a Zimbra Collaboration Server (ZCS Open Source Edition) 7.2 installation, but should work on earlier versions as well.
I use another script to backup the whole Zimbra installation, but that might be another blog post.

#!/bin/bash -x
# Backup of Zimbra mailboxes using zmmailbox
# Restore of mailbox should be performed using:
# /opt/zimbra/bin/zmmailbox -z -m user@host postRestURL -u https://HOST "//?fmt=tgz&resolve=skip" mailbox-name-date.tgz
MailBox="user1 user2 user3 userN"
DateToday=`date -I`
for name in $MailBox
sudo -u zimbra /opt/zimbra/bin/zmmailbox -z -m $ getRestURL "//?fmt=tgz" > mailbox-$name-$DateToday.tgz

The backup files are named mailbox-user1-20120802.tgz mailbox-user2-20120802.tgz …

Tags: , , , , , ,

Posted by

17 Jul 2012 Rename AVCHD files using Exiftools

Simple bash script to rename AVCHD/MTS/MOV files to match their recording date and time.

if [ -z "$1" ]; then
echo "Usage: ./ FILETYPE" 1>&2
echo "Example: ./ *.MTS" 1>&2
exit 1
for x in "$@"
exiftool '-FileName<DateTimeOriginal' -d %Y%m%d_%H%M_%%f.%%e "$x"

The resulting files will be named like YYYYMMDD_HHMM_BASENAME.ext ie 20120703_1635_05600.MTS

Exiftools can also be used to perform the renaming process in Windows as well using a command window

# exiftool "-FileName<DateTimeOriginal" -d %Y%m%d_%H%M_%%f.%%e *.MTS

This script has been tested on Canon Legria and on Panasonic HDC-SD800 video camera MTS-files and Nikon D7000 MOV-files with great success.

Tags: , , , ,

Posted by

02 Dec 2011 Grab several screenshots from specified window in linux

This was a short bash script I wrote to help document some startup problems on a server.
The script was grabbing screen dumps from iDRAC during boot on a RHEL6 server, but it can be used on other distributions as well since the console command xwd is common.

# Description:
# Grab screenshot of a specified X-window and wait X-seconds

# Use xwininfo to find the Window id to the window you are going to 
# grab screenshots from.

# filename for output

# seconds sleep between grabs

padding="000" # put as many padding zeros as you want on filename
for ((i=0; i<1000; i+=1))
        # Perform the actual screenshot grab
        xwd -id $xwininfo -out $outfile-${padding:${#i}}$i.xwd

        # Convert the xwd file to a better image format like PNG
        convert $outfile-${padding:${#i}}$i.xwd $outfile-${padding:${#i}}$i.png

        # Delete the converted XWD-file
        rm -f $outfile-${padding:${#i}}$i.xwd

        # wait 
        sleep $sleeping

Stop the script after you have grabbed enough screenshots.

I ended up with several files named outfile-000.png outfile-001.png ...
Deleted those files that were not needed and sent the images a documentation of the booting process.

Tags: , , , ,

Posted by

10 Sep 2010 Randomize filenames

This is a simple bash script to create random filenames of all jpg-files (*.jpg) in a folder using the linux commands mv, sha1sum and cut.

# Randomize filenames

for fname in *.jpg;
        mv "$fname" $(echo "$fname" | \
                sha1sum | \
                cut -f1 -d ' ' | \
                cut -b 1-5).jpg

The jpg-files can have names like


Tags: , , ,

Posted by