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
Posted by Hans-Henry Jakobsen
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: bash, EXIF, exiv2, jhead, JPG, NEF, rotate
Posted by Hans-Henry Jakobsen
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: bash, getRestURL, postRestURL, Zimbra, zmmailbox
Posted by Hans-Henry Jakobsen
Simple bash script to rename AVCHD/MTS/MOV files to match their recording date and time.
#!/bin/bash
if [ -z "$1" ]; then
echo "Usage: ./rename_video.sh FILETYPE" 1>&2
echo "Example: ./rename_video.sh *.MTS" 1>&2
exit 1
fi
for x in "$@"
do
exiftool '-FileName<DateTimeOriginal' -d %Y%m%d_%H%M%S_%%f.%%e "$x"
done
The resulting files will be named like YYYYMMDD_HHMMSS.ext ie 20120703_005600.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%S_%%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: avchd, bash, exiftools, rename
Posted by Hans-Henry Jakobsen
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.
#!/bin/bash
# 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.
xwininfo="0x4c0001a"
# filename for output
outfile="outfile-"
# seconds sleep between grabs
sleeping=2
padding="000" # put as many padding zeros as you want on filename
for ((i=0; i<1000; i+=1))
do
# 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
done
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: bash, convert, PNG, windowid, wxd
Posted by Hans-Henry Jakobsen