I have a NAS which holds all my pictures, and have it mounted on my xbmc as a network share. I want to automatically synchronize my pictures (NAS -> xbmc, one direction).
But, during the synchronization I want to resize the pictures to make them smaller on my XBMC.
so in short I would think the script should look like:
- diff of the 2 directories (recursivly), with output being only the files existing in the NAS and not on XBMC
- For each entry:
- copy the file
- apply the convert command
thanks for the reply!
but this doens't deal with if source contains directories with subdirectories, correct?
so ideally the script should check what folder the file is in, and recreate that same folder structure in the target ...
Think this is the tricky part
but this doens't deal with if source contains directories with subdirectories, correct?
thanks!
It's tricky, but it does deal with subdirectories.
Assume, that NAS was set to /usr4/nas, and the first file returned by find was /usr4/nas/2010/pic1.jpg. The result of this line of the script:
sets STR to 2010/pic1.jpg. The meaning of ${variable##pattern} is to remove the longest occurance of pattern from the front of the contents of variable. The variable file would have been /usr4/nas/2010/pic1.jpg and the value of $NAS would have been /usr4/nas, so the result is everything after /usr4/nas/, or 2010/pic1.jpg which includes the subdirectory.
Assuming XBMC was set to /xbmc, and taking it further
would test to see if /xbmc/2010/pic1.jpg existed -- properly assuming the directory structure from the source filesystem exists on the target filesystem. Likewise, the copy command assumes the same directory structure on the target filesystem. (It does assume that the directory structure exists on the target.)
There are two things that I would tweek:
First, use find piped to while rather than assuming that the output of the find command can be handled as a list to for.
Secondly, assuming Kshell or Bash, use [[ ]] to supply the test expression rather than the single bracket. The double bracketed expressions are more efficient because the evaluation is done by the shell and not by an external command (test).
In addition, if the script should make the directories on the target that don't exist, the following needs to be added:
This should go immediately before the copy.
Last edited by agama; 08-16-2010 at 08:37 PM..
Reason: corrected silly typos
some questions:
- I don't know the mk command, is mkdir also good?
- shouldn't it be: if [[ ! -d $targetd ]] (exclamation mark) because needs to create dir when it doesn't exist
- same for the file check, shouldn't it be with exclamation mark?
- added quotes around mk -p "$targetd" because had issue with spaces in dir name
when I run the script with a test directory:
test (dir)
_sub test (dir)
___testfile
_testfileroot
I get the following in the target dir
test2 (dir)
_sub test (dir)
___empty!
_testfileroot (dir)
___testfileroot
some questions:
- I don't know the mk command, is mkdir also good?
- shouldn't it be: if [[ ! -d $targetd ]] (exclamation mark) because needs to create dir when it doesn't exist
- same for the file check, shouldn't it be with exclamation mark?
- added quotes around mk -p "$targetd" because had issue with spaces in dir name
How embarassing. Yes, mkdir. I use plan 9's make which is mk, so that is what my fingers like to type.
Also, yes ! -d; another typo I hit $ instead of ! from the looks of my original post.
I cut/pasted the original script posted by rdcwayx and didn't even look to find the -f mistake. Yes, a bang in front of it to copy only the files that don't exist on the target (otherwise you'll overlay them with the smaller images).
I abhor filenames with spaces for just that reason. Quoting is the right thing to do if you don't have a choice about the filenames.
Quote:
when I run the script with a test directory:
test (dir)
_sub test (dir)
___testfile
_testfileroot
I get the following in the target dir
test2 (dir)
_sub test (dir)
___empty!
_testfileroot (dir)
___testfileroot
so think I've made a small error somewhere?
Not sure at the moment. I'll copy out the script you posted and try it here and add something if I see what is wrong.
---------- Post updated at 19:54 ---------- Previous update was at 19:35 ----------
I think the problem stems from the assumption by $(STR%/*} that STR contains a path. It doesn't for files that sit in the top level directory. Here's the whole script that I ran which created the right directories, and copied the things that weren't in the target:
Have a go with the changes to test $STR for a slant and see how that works.
I need a command or mini scripts that can find certain type of images file recursively from the current dir with files of minimum 736 width and resize them by "736 max width, relative height" and replace the source files. I currently have GD installed but can also install Imagemagick if needed, I'm... (5 Replies)
Hi guys,
I know that this topic has been discuss numerous times, and I have search the net and this forum for it.
However, non able to address the problem I faced so far.
I am on Solaris Platform and unable to install additional packages like the GNU date and gawk to make use of their... (5 Replies)
Hi,
I want to synchronize time on several AIX servers - I don't want to set very precise time value, but I want all the servers to have same time value.
How do I do that ?
thanks
Vilius (2 Replies)
I use HP-UX & need help with time.
I use a script to create a date stamp: /bin/date "+%m%d%H%M" to get: 12080826.
I need a way to use the "touch -t" command to create a
file with a timstamp 30 minutes prior to that stamp. (12080756)
Can anyone help? (9 Replies)
Hi,
I have 4 solaris 9(32-Bit) Sparc machines on the same subnet.
All 4 of them have different times( off by 10-15 mins).
I need to synchronize all 4 of them.
Please advise what I should do to sync them to the proper time, and with each other.
Thanks (3 Replies)
I am writing a program to display a database to the screen(xterm) and want to allow the window resize signal to increase/decrease the amount data that is displayed. I have a signal handler function for catching the SIGWINCH event and calling a function to reallocate the space for the windows... (0 Replies)