Welcome to Ebugg-i.com

Thanks for coming to Ebugg-i.com.

Ad blocker detected

Our website is made possible by displaying online advertisements to our visitors. We need to pay our bills (hosting charges) and we can't do that for free. Please consider supporting us by disabling your ad blocker on our website and whitelist our website.
Please disable ad blocker and reload this web page
Close this message

Opinions on bash script.

Posted on: Jun 28 2014 Category :Linux > Ubuntu Views: 1067 | Subscribe

I'd like some opinions on this script I wrote that organizes photos into a year/month directory structure out of my dropbox folder on a permanent loop, it's been changed many times over the years since I first scribbled it down, it got very long and convoluted, then recently I pretty much scrapped it and re-wrote it cutting away a lot of unnecessary bits. I'd like to know what people think of my code and if anyone has any constructive criticism of my bash techniqueCode:#!/bin/bash #~ run on: desktop #~ Photo Sorter #~ A script to sort photos in date ordered directories #~ Mark Skinner #~ Created 04/03/2012 #~ last modified 27/06/2014 #~ Requires jhead to be installedset -xwhile true; do # sleep for 5mins sleep 5m # determine files for iteration while read -d $'' photo ; do # obtain photo timestamp timestamp=$(jhead "$photo" | grep Date/Time) # strip full path name from photo photo=$(basename "$photo") # obtain year and month year=${timestamp:15:4} month=${timestamp:20:2} # if year and month both exist if [ $year ] && [ $month ]; then # rename photo whilst capturing new photo name renamed_photo=$(jhead -n%Y-%m-%d %H:%M:%S $HOME/Dropbox/Camera Uploads/"$photo" |awk -F '/' {'print $(NF)'}) # mv photo to new location mkdir -p $HOME/Pictures/$year/$month; mv -n $HOME/Dropbox/Camera Uploads/"$renamed_photo" $HOME/Pictures/$year/$month/ fi done<

Post your comments/solution

Get email updates. Virus Removal Tips, News, How to, Threat Alerts.

Bitdefender Antivirus for Mac and PC

Leave a comment!