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 simple bash script that is run by crontab every 5 minutes on a linux box.
It e-mails me the new address when a change of IP address is detected.
The script (ipchangemail.sh)
#!/bin/bash
# Check if IP-address has changed. If a change has occured, mail me the new address
# Add the following line to crontab if you would like it to be run every 5 minutes:
# */5 * * * * ./ipchangemail.sh
# The network interface I want to monitor
NET_INTERFACE=eth0
# File to keep the latest IP address
IP_FILE=myip.txt
# Mail to this address when a change occur
MAILTO=mail@example.com
# Read the previous IP address from file
source $IP_FILE
CURRENT_IP=`/sbin/ifconfig $NET_INTERFACE | sed -n "/inet addr:.*255.255.25[0-5].[0-9]/{s/.*inet addr://; s/ .*//; p}"`
if [ "$CURRENT_IP" != "$OLD_IP" ]
then
# Send email about address change
`echo "New IP address detected: $CURRENT_IP" | mail -s "New IP address" $MAILTO`
# Write new address to file
`echo "OLD_IP=$CURRENT_IP" > $IP_FILE`
fi
The script can be downloaded here.
Tags: bash, ifconfig, mail, sed
Posted by Hans-Henry Jakobsen
Query caching is a way to increase the performance of mysql by caching database queries.
It’s quite easy to do and only requires to edit one file, in Debian it’s called /etc/mysql/my.cnf
Add the following lines in the mysqld section
[mysqld] query-cache-type = 1 query-cache-size = 10M
restart the mysql daemon
# /etc/init.d/mysql restart
# mysql -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 33499 Server version: 5.0.32-Debian_7etch6-log Debian etch distribution Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> SHOW VARIABLES LIKE '%query_cache%'; +------------------------------+----------+ | Variable_name | Value | +------------------------------+----------+ | have_query_cache | YES | | query_cache_limit | 1048576 | | query_cache_min_res_unit | 4096 | | query_cache_size | 10485760 | | query_cache_type | ON | | query_cache_wlock_invalidate | OFF | +------------------------------+----------+ 6 rows in set (0.00 sec)
If you see something like the out above, caching is enabled.
Posted by Hans-Henry Jakobsen
man -t passwd | ps2pdf -> passwd.pdf
Tags: ps2pdf
Posted by Hans-Henry Jakobsen
This is a little script I’ve written to correct all my image files since the EXIF timestamp information is one hour out of sync. The filenames have been renamed to comply to the EXIF information and has to be renamed again because of the one hour scew. The filename can look something like this 20080102-1201_DSC_0910.JPG where the name is built up like YYYYMMDD-HHMM_Original_Filename.JPG
Remember to backup your imagefiles before you continue. You have been warned!
This is the files we are going to rename
20080102-1201_DSC_0910.JPG 20080105-1923_DSC_1006.JPG 20080111-1220_DSC00189.JPG 20080122-0929_DSC00190.JPG
The mmv command is a command that lets you move/copy/append/link multiple files by wildcard patterns. It can be installed in Debian (or Debian based distributions like Ubuntu) by issuing the command
# aptitude install mmv
Now rename the files back to their original name
# mmv "*_DSC*" "DSC#2"
The result after this operation looks like this
DSC_0910.JPG DSC_1006.JPG DSC_1179.JPG DSC_1302.JPG DSC_1587.JPG
Next adjust the EXIF information stored in the image files to fix the one hour difference. This can be done using different EXIF tools like exiftool, but I will show you how it can be done using jhead and exiv2. The advantage with exiv2 is that it can also handle Nikon NEF files while jhead only can prosess JPG.
The current timestamp can be determined as follows
# exiftool DSC_0910.JPG | grep "File Mo"
The result in this case is
File Modification Date/Time : 2008:01:02 08:34:09
# exiftool -AllDates+=1 DSC_0910.JPG
# jhead -ta +1 DSC_0910.JPG
Install the jhead package using aptitude as mentioned earlier for the mmv package
# exiv2 ad -a 1 DSC_0910.JPG
It is now time to rename the files back to the YYYYMMDD-HHMM_Original_Filename.JPG format I used before this operation. This operation has been describe in a previous post named Rename image files according to EXIF date
exiv2 -r'%Y%m%d-%H%M_:basename:' rename $(ls D*)
#!/bin/bash -x # Needed software: # exiftool # exiv2 # mmv # Script tested on Nikon D80 and Sony Cybershot DSC-W12 files # Make a printout of how the files look like now ls -l > repair_name_and_exif_before.txt # Rename files to remove date formatting back to original name mmv "*_DSC*" "DSC#2" # Change EXIF info on JPG files (order is important) exiftool -overwrite_original -AllDates+=1 D*.JPG # Preserve date/time of original file when writing exiftool -overwrite_original '-DateTimeOriginal>FileModifyDate' D*.JPG # Change EXIF info on NEF files (order is important) exiftool -overwrite_original -AllDates+=1 '-DateTimeOriginal>FileModifyDate' D*.NEF # Preserve date/time of original file when writing exiftool -overwrite_original '-DateTimeOriginal>FileModifyDate' D*.NEF # Rename files back to date formatting (YYYYMMDD-HHMM_Filename) based on the new EXIF info exiv2 -r'%Y%m%d-%H%M_:basename:' rename $(ls D*) # Make a printout of how the files look like after conversion ls -l > repair_name_and_exif_after.txt
Tags: Debian, EXIF, exiv2, jhead, JPG, mmv, NEF, Nikon, rename, Sony
Posted by Hans-Henry Jakobsen