LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   looking to create a script that... (https://www.linuxquestions.org/questions/linux-newbie-8/looking-to-create-a-script-that-586592/)

Geminias 09-22-2007 01:21 PM

looking to create a script that...
 
I need a script that will sync two directories.

Directory1: file1 dir1
dir1: file2

Directory2: file3

After running the sync script the two directories would look like:

Directory1: file1 file3 dir1
dir1: file2

Directory2: file1 file3 dir1
dir1: file2

If this is an easy script to write could someone write one... I know some bash but I'm struggling to write this script bc I don't know enough.

GrapefruiTgirl 09-22-2007 01:51 PM

Code:


#!/bin/sh
DIR1=/path/to/dir1
DIR2=/path/to/dir2

for i in $DIR1/* ; do
cp -Rup $i $DIR2/$i
done

for i in $DIR2/* ; do
cp -Rup $i $DIR1/$i
done

Something as simple as this should work. Please test it first before depending on it to work perfectly. :)

Geminias 09-22-2007 02:05 PM

Thank you GrapefruitGirl,

there was one minor problem, here's a working version:

Code:

#!/bin/bash

#Script to synchronize two directories

DIR1=path/to/dir1
DIR2=path/to/dir21

for i in $DIR1/* ; do
cp -Rup "$i" "$DIR2/`basename $i`"
done

for i in $DIR2/* ; do
cp -Rup "$i" "$DIR1/`basename $i`"
done


GrapefruiTgirl 09-22-2007 02:09 PM

Hey cool :) I'm not great with bash either; can ALWAYS learn something new. Thanks!

Geminias 09-22-2007 05:28 PM

I'm not sure why this script doesn't work for an nfs mounted folder. Could someone explain/offer a solution?

iAlta 09-22-2007 05:54 PM

Are you sure you have permission to write to the nfs mounted folder?


All times are GMT -5. The time now is 05:43 PM.