Unix/Linux Go Back    

UNIX for Dummies Questions & Answers This forum is closed for new posts. Please post beginner questions to learn unix and learn linux in this forum UNIX for Beginners Questions & Answers

Copy and modify a file if the original has changed

UNIX for Dummies Questions & Answers

Thread Tools Search this Thread Display Modes
Old Unix and Linux 06-27-2013   -   Original Discussion by SebSnake
SebSnake SebSnake is offline
Registered User
Join Date: Jun 2013
Last Activity: 27 June 2013, 11:51 AM EDT
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Copy and modify a file if the original has changed

Hi there,

I have built up my own little "cloud" for my family as the amount of computers grows all day. By now we use 3 smartphones, 2 notebooks und 4 PCs, so this "home cloud" was made to store all personal data (photos, documents,...) and do a backup once in a while. It is running on a Ubuntu Server 12.10 (not sure right now) as a headless configuration with encrypted ssh to work on it. A second HDD is turned on just once a day automatically to do a full backup of all the important data.

All devices have an UPnP / DLNA connection to this cloud which is running minidlna and samba. As there are 2 SmartTVs connected to the network as well by WLAN, we like to see and show our taken photos "on the big screens". For that, I would like to scale down all photos to max 1920x1080 and store them as JPG with 80% compression. Therefore I use the imagemagick package:

mogrify -format jpg -resize 1920x1080 -quality 80

The thing is, I want to store the photos originals as well. This is my now running setup / configuration:

- There are public shares in samba ("Photos", "Music", "Videos") as well as private ones. Photos has subfolders for each family member capable of using a camera. Thats where the originals are stored.

- There is a cronjob which checks every 30 Minutes for new files, converts them to jpg and resizes them if necessary. It looks like this:

*/30 8-23 * * * rsync -rltDvu --ignore-existing /files/samba/Photos/ /files/dlna/Pictures; 
     find /files/dlna/Pictures -type f -not -name "*.jpg" 
     -exec mogrify -format jpg -quality 100 {} \; 
     -exec rm {} \;; 
     find /files/dlna/Pictures -iname "*.jpg" 
     -exec mogrify -resize 1920x1080 -quality 80 {} \;

(Everything in one line, just modified for better reading.)

- There is another cronjob which deletes the downscaled versions if the original is removed. Runs once a week:

0 2 * * 1 rsync -rltDvu --delete --ignore-existing /files/samba/Photos /files/dlna/Pictures

This setup has 2 problems:

1st: When you modify a picture (like photoshop stuff), and overwrite the original, it wont be updated, as the sync process's --ignore-existing is set.
This tag is set so it wont sync all the originals because of downsized versions.

2nd: Running the job every 30 minutes is bad. If you load pictures into the cloud, you'll have to wait (worst case) 30 minutes to have them appear in DLNA clients. But running it more frequently is bad as well, as the job does some heavy load (cpu, ram) while running because of the find- and mogrify-stuff.

Now I thought about making a small program (I can code c++/c#), which simply creates a dummy file (like //cloud/dlna/.resize) in the cloud. The cronjob would look like:

* * * * * if [ -f /files/dlna/.resize ]; then 
     <<do all the magic here>>; 
     rm -f /files/dlna/.resize;

(Again, everyhing in one line.)

Would solve the 2nd problem, but not the first.

Do you have some suggestions how to solve problem #1? Something better than "find every picture and do a mogrify-thing" on it? I thought about something like creating dummy files somewhere to sync (compared to those) just newer or modified files. But I dont know how to do it.
Sponsored Links
Old Unix and Linux 06-27-2013   -   Original Discussion by SebSnake
alister alister is offline
Registered User
Join Date: Dec 2009
Last Activity: 11 June 2014, 8:40 PM EDT
Posts: 3,231
Thanks: 179
Thanked 976 Times in 790 Posts
If you only need to run the job on Linux, perhaps you can use inotifywait to listen for file creation and modification, solving both problems.

Sponsored Links

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
copy original files from links venkatababu UNIX for Advanced & Expert Users 1 10-01-2012 05:26 PM
how to copy files and record original file location? willie8605 UNIX for Dummies Questions & Answers 4 04-16-2012 03:49 PM
Help with a shell script to modify one line and copy the next 9 to same file Teroc Shell Programming and Scripting 5 10-30-2009 08:38 AM
Where can I get original copy of Unices laduch UNIX for Dummies Questions & Answers 1 06-10-2008 09:14 AM
command to copy files with original ownership need_help UNIX for Advanced & Expert Users 3 02-08-2008 07:46 PM

All times are GMT -4. The time now is 09:53 AM.