UNIX gurus please teach me..

Discussion in 'OT Technology' started by babygodzilla, Apr 17, 2007.

  1. babygodzilla

    babygodzilla I love rice

    Joined:
    Nov 5, 2001
    Messages:
    3,108
    Likes Received:
    0
    ... how to make a script that automatically syncs folder A with folder B whenever files in folder B and its subfolders are saved/updated/changed.

    i was told to use "sync," but i have very little knowledge of UNIX so :dunno:..
     
  2. RiSk

    RiSk New Member

    Joined:
    Jun 8, 2004
    Messages:
    6,564
    Likes Received:
    0
    Location:
    Irving, Texas
    I will tell you now you are looking at a cron job more likley then a "script" that will automaticly do it. How big is said folder A? you could write a simple script that looks like


    !#/bin/bash

    cp /folder/a /folder/b

    and set it to run 1 time every hour, or day, min w/e Be careful as it will be using the files so no one will be able to update or save during the time of the cron job.
     
  3. deusexaethera

    deusexaethera OT Supporter

    Joined:
    Jan 27, 2005
    Messages:
    19,712
    Likes Received:
    0
    Does UNIX have a feature like Shadow Copies that he could use to sync files while they're being used by other people/processes?
     
  4. babygodzilla

    babygodzilla I love rice

    Joined:
    Nov 5, 2001
    Messages:
    3,108
    Likes Received:
    0
    thanks, but i dont want a cron job. i will be editing and making frequent changes to files in folder B, and i want folder A to be synced with folder B as soon as i make a change/save/update to files in folder B.
     
  5. Penguin Man

    Penguin Man Protect Your Digital Liberties

    Joined:
    Apr 27, 2002
    Messages:
    21,696
    Likes Received:
    0
    Location:
    Edmonton, AB
    Code:
    while [[ 1 ]]; do
        rsync /dir/a/ /dir/b;
        rsync /dir/b/ /dir/a;
        sleep 5;
    done;
    :dunno:

    Edit: Oh, I was assuming that either /dir/a or /dir/b can change and you'd like them to be in sync with each other. If you're just going to be modifying B and would like A to update, then you don't need the first line in the while loop. But if this is the case, why not just create a symlink?
     
  6. RiSk

    RiSk New Member

    Joined:
    Jun 8, 2004
    Messages:
    6,564
    Likes Received:
    0
    Location:
    Irving, Texas
    The Simlink would be the best, but if any thing happned to folder A , folder b would be owned as well, as for not having a cron job... then you will have to write a script that will run as a deamon and watch that folder for changes and then sync / save / w/e based on that.
     
  7. babygodzilla

    babygodzilla I love rice

    Joined:
    Nov 5, 2001
    Messages:
    3,108
    Likes Received:
    0
    :rofl: i really appreciate the help guys. the thing is, i didnt understand a word u guys said in the last 2 posts... symlink? save/ w/e ?

    but yeah pretty much only folder B will be changed, and folder A just has to be synced to it. so how do i go about a symlink?

    edit: oh... i just realized symlink is a symbolic link.
     
  8. retorq

    retorq What up bitch??

    Joined:
    Dec 14, 2006
    Messages:
    6,061
    Likes Received:
    0
    Location:
    Mohave Desert
    man ln

    w/e = what ever
     
  9. RiSk

    RiSk New Member

    Joined:
    Jun 8, 2004
    Messages:
    6,564
    Likes Received:
    0
    Location:
    Irving, Texas
    [email protected] ~/Desktop $ ln --help
    Usage: ln [OPTION]... [-T] TARGET LINK_NAME (1st form)
    or: ln [OPTION]... TARGET (2nd form)
    or: ln [OPTION]... TARGET... DIRECTORY (3rd form)
    or: ln [OPTION]... -t DIRECTORY TARGET... (4th form)
    In the 1st form, create a link to TARGET with the name LINK_NAME.
    In the 2nd form, create a link to TARGET in the current directory.
    In the 3rd and 4th forms, create links to each TARGET in DIRECTORY.
    Create hard links by default, symbolic links with --symbolic.
    When creating hard links, each TARGET must exist.

    Mandatory arguments to long options are mandatory for short options too.
    --backup[=CONTROL] make a backup of each existing destination file
    -b like --backup but does not accept an argument
    -d, -F, --directory allow the superuser to attempt to hard link
    directories (note: will probably fail due to
    system restrictions, even for the superuser)
    -f, --force remove existing destination files
    -n, --no-dereference treat destination that is a symlink to a
    directory as if it were a normal file
    -i, --interactive prompt whether to remove destinations
    -s, --symbolic make symbolic links instead of hard links
    -S, --suffix=SUFFIX override the usual backup suffix
    -t, --target-directory=DIRECTORY specify the DIRECTORY in which to create
    the links
    -T, --no-target-directory treat LINK_NAME as a normal file
    -v, --verbose print name of each linked file
    --help display this help and exit
    --version output version information and exit

    The backup suffix is `~', unless set with --suffix or SIMPLE_BACKUP_SUFFIX.
    The version control method may be selected via the --backup option or through
    the VERSION_CONTROL environment variable. Here are the values:

    none, off never make backups (even if --backup is given)
    numbered, t make numbered backups
    existing, nil numbered if numbered backups exist, simple otherwise
    simple, never always make simple backups

    Report bugs to <[email protected]>.
    [email protected] ~/Desktop $
     
  10. Peyomp

    Peyomp New Member

    Joined:
    Jan 11, 2002
    Messages:
    14,017
    Likes Received:
    0
    If you literally want them to be the same, you do:

    PHP:
    man ln
    And look at the -s option.

    If you want to do this across servers, you need to google 'rsync' and 'nfs'
     

Share This Page