Archive for May, 2010

Set Modified Time to Date and Time Picture was Taken (in Linux)

Saturday, May 22nd, 2010

Oh no! I just moved 3 gigs of pictures, afterwards realizing that the modified-time was changed from the time the picture was taken to the time the file was moved. What a mess, I thought, since I always refer to the modified-time when I wonder when a picture was taken.

exiv2 and touch to the rescue!

exiv2 will tell you, among a ton of other things, the time the picture was taken, and touch will allow you to change the modified-time of the image.

Note:Any command below, spread across multiple lines, is done so for clarity. To use the command, the line breaks must be removed such that the entire command is on one line!

This is the output of exiv2:

File name       : my_picture.jpg
File size       : 77443 Bytes
MIME type       : image/jpeg
Image size      : 425 x 543
Camera make     : Canon
Camera model    : Canon PowerShot SD1100 IS
Image timestamp : 2010:04:26 20:06:07
Image number    : 100-2025
Exposure time   : 1/60 s
Aperture        : F4.9
Exposure bias   : 0
Flash           : Yes, auto, red-eye reduction
Flash bias      : 0 EV
Focal length    : 18.6 mm
Subject distance: 266
ISO speed       : 250
Exposure mode   : Easy shooting (Auto)
Metering mode   : Multi-segment
Macro mode      : Off
Image quality   : Fine
Exif Resolution : 1848 x 2360
White balance   : Auto
Thumbnail       : JPEG, 7866 Bytes
Copyright       :
Exif comment    :

Now you just use grep to find the Image timestamp line:

exiv2 my_image.jpg | grep timestamp
Image timestamp : 2010:04:26 20:06:07

Now use awk to massage that date into almost the touch-required format of YYYYMMDDHHMM.SS

exiv2 my_image.jpg |
  grep timestamp |
    awk '{split($5,t,":");print $4,t[1],t[2],".",t[3]}'
2010:04:26 20 06 . 07

Now use sed to remove the space and colons to complete the formatting

exiv2 my_image.jpg |
  grep timestamp |
    awk '{split($5,t,":");print $4,t[1],t[2],".",t[3]}'  |
      sed 's/[:, ]//g'
201004262006.07

And the final command, to actually touch an image:

touch my_image.jpg -t
  `exiv2 my_image.jpg |
    grep timestamp |
      awk '{split($5,t,":");print $4,t[1],t[2],".",t[3]}' |
        sed 's/[:, ]//g'`

For an entire directory:

find *.jpg |
  while read f; do
    touch "${f}" -t `
      exiv2 "${f}" |
        grep timestamp |
          awk '{split($5,t,":");print $4,t[1],t[2],".",t[3]}' |
            sed 's/[:, ]//g'`;
  done

Use ImageMagick’s convert Command Instead of jpegorient in KDE

Wednesday, May 19th, 2010

snapshot1

One annoying thing that has plagued my laptop is that right-clicking a JPEG in Dolphin makes a menu fly out with unusable options to rotate and flip the image. They don’t work because jpegorient doesn’t come with openSUSE 11.1, and I don’t know what it is or how to get it. I’ve been using the convert command (a part of ImageMagick) from a command line, so I wondered if I could make the Actions menu use it as well.

I edited the ServiceMenu file for the Actions menu, which is at /usr/share/kde4/services/ServiceMenus/jpegorient.desktop on my computer. You can execute locate jpegorient.desktop or find jpegorient.desktop if you don’t see it at that path. The changes are below in bold.

[Desktop Action jpegRot90]
Name=Rotate Clockwise
Icon=object-rotate-right
Exec=convert -rotate 90 %F %F

[Desktop Action jpegRot270]
Name=Rotate Counter-Clockwise
Icon=object-rotate-left
Exec=convert -rotate 270 %F %F

#[Desktop Action jpegRot180]
#Name=Rotate 180
#Icon=misc
#Exec=jpegorient +180 %F

[Desktop Action jpegFlipV]
Name=Flip Vertically
Icon=2uparrow
Exec=convert -flip %F %F

[Desktop Action jpegFlipH]
Name=Flip Horizontally
Icon=2rightarrow
Exec=convert -flop %F %F

SSH Without Password

Tuesday, May 18th, 2010

I was looking for a quick and dirty way to SSH into a handful of hosts. I SSH into these hosts all day long, and I was looking for a way to skip the password prompt (I’m way too much into efficiency — every second counts!). I wasn’t interested in learning how to set up the public/private key authentication. I just wanted to automate the login so all I would need to type is goto host. Obviously this is less than secure, but I’m not overly concerned with security at my workstation.

Here’s what I came up with:

1) a file named goto.passwd
– which contains hostnames, usernames, and passwords (e.g. myhost myuser mypassword)
2) a script named goto
– which accepts one parameter (e.g. goto myhost)
– parses the goto.passwd file looking for that host
– and then passes that info to
3) a script borrowed from here
– and slightly modified.

Here is an example (the command is simply goto myhost and I’m instantly in.):

john@jslinux:~> goto myhost
spawn ssh user@myhost
user@myhost’s password:
Last login: Tue May 18 11:31:05 2010 from 1.2.3.4
-bash-3.2$

Here are the scripts (you can also download them as a zip or tar):

goto.passwd

myhost root password
myotherhost root passwordforroot
anotherhost root password12345

goto

#!/bin/bash
host=$1
user=`cat goto.passwd | grep -e ^$host | awk '{print $2}'`
pass=`cat goto.passwd | grep -e ^$host | awk '{print $3}'`
goto.expect $user $pass $host

goto.expect

omitted. see zip or tar file below.


goto.tar
goto.zip