Sponsored Content
Top Forums Shell Programming and Scripting how to synchronize different dirs Post 302099166 by Perderabo on Saturday 9th of December 2006 07:08:08 PM
Old 12-09-2006
This is untested, but it should be close:
Code:
#! /usr/bin/ksh
for newdir in newdir1 newdir2 newdir3 newdir4 ; do
      olddir=${newdir#new}
      mkdir $newdir
      for dir in dir1 dir2 dir3 dir3 ; do
               if [[ $dir != $olddir ]] ; then
                    cd $dir
                     ls | while read file ; do
                            newfile=${file%.txt}
                            [[ -f ../${newdir}/$newfile || -f ../${olddir}/$file ]] || cp $file ../${newdir}/${newfile}
                     done
                     cd ..
              fi
       done
done
exit 0

This way you copy the file to $newdir only if it is not already there. Also the presense of the file in the old directory will inhibit the copy. From what you said, this will save copying thousands of files. Now no rm step is needed. The files renamed as they were copied, no separate rename step needed either.
 

9 More Discussions You Might Find Interesting

1. Programming

synchronize as in java

Hi, I am trying to implement the synchronize feature of java using C. I am using a semaphore for the same. I have a wrapper called "synch" to which I pass the function pointer(any_fn). This pointer points to the function (my_fn) which needs to be synchronized. However to create the semaphore I... (8 Replies)
Discussion started by: linuxpenguin
8 Replies

2. Shell Programming and Scripting

How to synchronize all the linux machine?

Hi, I have three Linux machine have three different times. Can I synchronize them using one process? I have root access. Thanks! (1 Reply)
Discussion started by: whatisthis
1 Replies

3. Programming

need a way to synchronize processes

I am writing a program in C for my networking class, so I am relatively new to this. To begin, I have 7 processes that need do send messages to every other one, and every one of them needs to receive the messages sent by others. I am using fork() to create 6 more processes. The message... (1 Reply)
Discussion started by: inabramova
1 Replies

4. UNIX for Advanced & Expert Users

synchronize processes

hi. i am writing a c program under bash shell. i would like to use semaphore functions like sem_wait(), sem_post() and i included <semaphore.h> and it compailes fine but when i try to run it gives me an error "undefined reference to sem_wait() , sem_post() , sem_init()" what have i missed... (2 Replies)
Discussion started by: emil2006
2 Replies

5. Programming

synchronize two processes

i am trying to synchronize between father process and son process created by fork() command, to print simultaneously. my program is written in c under bash shell. the compile goes ok but when i try to run nothing happens and the program doesnot end. my code is: #include <stdio.h>... (1 Reply)
Discussion started by: emil2006
1 Replies

6. Shell Programming and Scripting

Synchronize Files-Help

Hi, I have two servers1&2, one is not in the network. Cant communicate from it to other servers. The second one can communicate to above mentioned server. I am trying a script which synchronizes files between server 1 an 2? server1: cant communicate to any other servers server2: can... (4 Replies)
Discussion started by: Tuxidow
4 Replies

7. Shell Programming and Scripting

How to synchronize using FTP

Hi everyone! I need to write a script that will synchronize two servers using FTP. So basically the script will get only the files that exist on the remote server that do not exist on the local server. Is there an option to do this when using mget? If not, is there a way to copy over only the... (2 Replies)
Discussion started by: Fatbob
2 Replies

8. UNIX for Dummies Questions & Answers

**HELP** how to do a listing of dirs and all sub dirs only

I am trying to get a listing of ALL directories only under /export (as an example). I can get all the dirs directly under /export but I need any sub dirs under those dirs. I've looked (here and google) but can not find anything that works (4 Replies)
Discussion started by: bbraml
4 Replies

9. UNIX for Advanced & Expert Users

How to synchronize two different files?

Hello, I have the latest stable release of a UNIX-like O.S. in the ISO format, and want to synchronize it with the latest Release Candidate (RC) of it, in order to reducing bandwidth usage. The ISO images for that O.S. is provided via different protocols including rsync, FTP and HTTP Is this... (4 Replies)
Discussion started by: temp-usr
4 Replies
FileBrowser(3I) 					    InterViews Reference Manual 					   FileBrowser(3I)

NAME
FileBrowser - browse and/or select file names SYNOPSIS
#include <InterViews/filebrowser.h> DESCRIPTION
FileBrowser is a StringBrowser that displays file names. In addition to the standard StringBrowser constructor parameters, the FileBrowser constructor takes a directory name as an argument. The FileBrowser scans the corresponding directory, appending the file names to its list of strings. FileBrowser lets the user choose a file name, and the application queries the FileBrowser for the chosen file. PUBLIC OPERATIONS
FileBrowser(ButtonState*, const char* dir, int rows, int cols, boolean uniqueSel, int highlight, const char* done) FileBrowser(const char* name, ButtonState*, const char*, int, int, boolean, int, const char*) Create a new FileBrowser object. The ButtonState, rows, cols, uniqueSel, highlight, done, and name parameters have semantics iden- tical to those of the corresponding StringBrowser parameters. The dir parameter specifies the directory to search for file names. Internally, FileBrowser prepends dir to relative path specifications in operations that require them, thus avoiding a chdir(2). boolean IsADirectory(const char*) Return whether or not the given relative path corresponds to a valid directory. boolean SetDirectory(const char* newdir) Change the search directory to newdir if that directory is accessible. The function returns true if successful. const char* GetDirectory() Return the name of the search directory. const char* ValidDirectories(const char* path) Given a path string, return the largest substring (starting from the beginning of path) that represents a valid path. The substring is returned in a static buffer and should be copied before use. const char* Normalize(const char* path) Return a normalized version of path with all spurious slashes, dots, and tildes interpreted. The normalized path is returned in a static buffer and should be copied before use. const char* Path(int i) Return the ith string as it appears in the FileBrowser. This function prepends the search directory to the string, normalizes the concatenation, and returns the result. void RereadDirectory() Rescan the current directory without updating the FileBrowser's appearance. virtual void Update() Rescan the current directory and update the FileBrowser's appearance to reflect any changes in the set of files it should display. void SetTextFilter(const char*) void SetDirectoryTextFilter(const char*) void SetModeFilter(int) void SetDirectoryModeFilter(int) By default, FileBrowser displays all the files and directories it finds in the search directory. These functions provide some con- trol over the entries that FileBrowser displays. SetTextFilter specifies a regular expression (see Regexp(3I)) to match against file names. SetDirectoryTextFilter serves a similar role for directory names. SetModeFilter and SetDirectoryModeFilter specify the mode (see chmod(1)) that displayed files and directories should have. Only files and directories that match both the regular expression and the mode will appear in the FileBrowser. Passing nil for the regular expression or 0 for the mode restores the default behavior. PROTECTED OPERATIONS
void UpdateStrings() Explicitly update the FileBrowser's appearance to reflect any changes in the set of files it should display without rescanning the directory. virtual boolean Acceptable(const char*) Return whether the given file name is an acceptable name. By default, files that conform to the text or mode filter specifications are acceptable. Only acceptable files will be displayed by UpdateStrings. SEE ALSO
Interactor(2I), Button(3I), StringBrowser(3I), Regexp(3I), chmod(1) InterViews 30 November 1989 FileBrowser(3I)
All times are GMT -4. The time now is 07:52 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy