Sponsored Content
Top Forums Shell Programming and Scripting Synchronize pictures & resize at the same time Post 302445360 by agama on Sunday 15th of August 2010 04:12:05 PM
Old 08-15-2010
Quote:
Originally Posted by Joeba
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:

Code:
  STR=${file##$NAS/}

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

Code:
if [ -f $XBMC/$STR ];

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.

Code:
find $NAS -type f | while read file
do
 ....
done

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).

Code:
if [[ ! -f $XBMC/$STR ]]

In addition, if the script should make the directories on the target that don't exist, the following needs to be added:

Code:
targetd=$XBMC/${STR%/*}   # get the target dir by chopping off the basename
if [[ ! -d $targetd ]]
then
    mkdir -p $targetd
fi

This should go immediately before the copy.

Last edited by agama; 08-16-2010 at 08:37 PM.. Reason: corrected silly typos
 

8 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

How do I send pictures in email?

I know how send a html page through mailx, but how do I show the pictures(gif,jpeg,etc.) in the email? (4 Replies)
Discussion started by: Thomas
4 Replies

2. Programming

curses & window resize issues

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)
Discussion started by: kwaz
0 Replies

3. UNIX for Advanced & Expert Users

Solaris 9: How to set time/Synchronize

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)
Discussion started by: 0ktalmagik
3 Replies

4. Shell Programming and Scripting

HP-UX & need help with time

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)
Discussion started by: obrien2003
9 Replies

5. AIX

Synchronize time on several AIX servers ?

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)
Discussion started by: vilius
2 Replies

6. Shell Programming and Scripting

Convert Epoch Time to Standard Date and Time & Vice Versa

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)
Discussion started by: DrivesMeCrazy
5 Replies

7. Programming

DATE & TIme

Can we select the datetime from oracle database in “hhmmssnnnccyymmdd” format ? please help to solve this..... (2 Replies)
Discussion started by: Sanal
2 Replies

8. Shell Programming and Scripting

How to find & auto resize images?

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)
Discussion started by: Frozen77
5 Replies
All times are GMT -4. The time now is 10:25 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy