LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-22-2007, 02:21 PM   #1
Geminias
Member
 
Registered: Sep 2005
Posts: 201

Rep: Reputation: 30
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.
 
Old 09-22-2007, 02:51 PM   #2
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
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.

Last edited by GrapefruiTgirl; 09-22-2007 at 02:52 PM.
 
Old 09-22-2007, 03:05 PM   #3
Geminias
Member
 
Registered: Sep 2005
Posts: 201

Original Poster
Rep: Reputation: 30
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

Last edited by Geminias; 09-22-2007 at 03:08 PM.
 
Old 09-22-2007, 03:09 PM   #4
GrapefruiTgirl
LQ Guru
 
Registered: Dec 2006
Location: underground
Distribution: Slackware64
Posts: 7,594

Rep: Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556Reputation: 556
Hey cool I'm not great with bash either; can ALWAYS learn something new. Thanks!
 
Old 09-22-2007, 06:28 PM   #5
Geminias
Member
 
Registered: Sep 2005
Posts: 201

Original Poster
Rep: Reputation: 30
I'm not sure why this script doesn't work for an nfs mounted folder. Could someone explain/offer a solution?
 
Old 09-22-2007, 06:54 PM   #6
iAlta
Member
 
Registered: Oct 2005
Distribution: Ubuntu 7.10, OpenSUSE 10.3, Linux Mint, Arch
Posts: 92

Rep: Reputation: 15
Are you sure you have permission to write to the nfs mounted folder?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Create a script to display file name, Inode, and size of any file. Has to be a script JaxsunApex Linux - Newbie 7 01-29-2007 09:15 PM
How to create a Create script "easier"? lorio Linux - Newbie 6 10-10-2006 07:05 PM
Need help to create a script barneyt Programming 2 08-18-2006 05:11 PM
How to create many by a script kelper Linux - General 11 09-24-2003 04:09 PM
How do I create a script? ACURA TL-S Linux - Newbie 1 08-03-2003 10:58 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:23 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration