msgbartop
A chronological documentation test project, nothing serious, really!
msgbarbottom

13 Nov 2012 Script to delete files listed in a file

This is a short one liner bash script to delete files in a file.
The script also handles filenames with space in them.


$ while read file; do rm "$file"; done < filename.txt

To generate a filename.txt file by searching for a specific pattern you can use the following command

$ find / -type f -name "filname*" > filename.txt

You should verify the files you are about to delete before you invoke this script!

Tags: ,

Posted by

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)

20120924-1320_DSC1234.JPG
20120924-1320_DSC1234.NEF
...

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
BackupFolder="/backup/zimbra"
MailBox="user1 user2 user3 userN"
DateToday=`date -I`
for name in $MailBox
do
sudo -u zimbra /opt/zimbra/bin/zmmailbox -z -m $name@pario.no getRestURL "//?fmt=tgz" > mailbox-$name-$DateToday.tgz
done

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

Tags: , , , , , ,

Posted by

23 May 2012 Rescue a damaged disk using GNU ddrescue

GNU ddrescue (gddrescue) is a linux data recovery tool. It copies data from one file or block device (harddisc, cdrom, etc) to another, trying hard to rescue data in case of read errors.
It can also be used as a forensic cloning tool.

Installing gddrescue in Ubuntu linux

# aptitude install gddrescue

The command to use for gddrescue is ddrescue, don’t ask me why it is not called gddrescue.

First you copy as much data as possible, without retrying or splitting sectors.
This example rescues data from one disk to another

# ddrescue --force /dev/sda /dev/sdb logfile.ddrescue

Warning! This overwrites content on /dev/sdb

When you use a log file you can stop ddrescue any time by pressing Ctrl+ C to interrupt the process.

You restart it again with the same parameters and ddrescue will resume from where it was before it was interrupted. This is good to know since this can be a time consuming process.

Now let it retry previous errors reported in the logfile 3 times, using uncached reads

# ddrescue --force --direct --max-retries=3 /dev/sda /dev/sdb logfile.ddrescue
Press Ctrl-C to interrupt
Initial status (read from logfile)
rescued:        2 TB,  errsize:   69632 B,  errors:     136
Current status
rescued:        2 TB,  errsize:   49152 B,  current rate:      256 B/s
   ipos:   916972 MB,   errors:      96,    average rate:      359 B/s
   opos:   916972 MB,     time from last successful read:       0 s
Retrying bad sectors... Retry 1

If that fails you can try again but retrimmed, so it tries to reread full sectors

# ddrescue --force --direct --retrim --max-retries=3 /dev/sda /dev/sdb logfile.ddrescue

You should now have rescued some data that you can continue your rescue work with.
There may be another post about that later.

Rescue a bad CDROM using ddrescue

# ddrescue -n -b2048 /dev/cdrom cdimage.img logfile.ddrescue
# ddrescue -d -b2048 /dev/cdrom cdimage.img logfile.ddrescue

The cdimage.img file can then be mounted as a loop file or written to a CDROM.

Tags: , , ,

Posted by

02 Feb 2012 Recursively symlinking files

This is a short script I use to symlink all my JPG image files on my file server to a flat folder accessible to my DLNA enabled devices.
My files are organized in year folders and under each year there are month folders:

-2011
--2011-01
--2011-02
--2011-03
...
-2012
--2012-01

I avoid duplicate symlinks by using file names like 20110102-1234_DSC…JPG or YYYYMMDD-HHMM_OriginalFileName.JPG

The script looks like this

#!/bin/bash 

SRC="/media/Images"
DEST="/media/SymlinkTarget"

# Create a symlink under $DEST for each JPG file under $SRC
find $SRC -type f | grep -i jpg | while read PATHNAME; do
        NEW="$DEST";
        echo "$NEW";
        ln -s "$PATHNAME" "$NEW";
done

Tags: , ,

Posted by