<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
  <title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Ricks,<br>
I tried the following.Its working fine.<br>
But instead of rsync we are using unison.<br>
when i tried to use unison.it is not working<br>
The only change i made is <br>
<pre wrap="">nohup unison $WATCHPT/$FNAME remotemachine:$WATCHPT/ \
         >>/dev/null 2>&1 &    </pre>
unison is installed in my pc.and i checked this unison working.that was
fine.but with above code it is not working for me.<br>
can you please help me.<br>
<br>
Regrads<br>
shibuthomas<br>
Rick Stevens wrote:
<blockquote cite="mid:4E0B514E.4080700@nerd.com" type="cite">
  <pre wrap="">On 06/29/2011 12:08 AM, ShibuThomas wrote:
  </pre>
  <blockquote type="cite">
    <pre wrap="">Hi ricks,

I wrote a one shell script which contains code for synchronize files
between two machines.I want to execute this script every 2 second.How
can I do this?.When I gone through net found that usually cron job is
used for doing same.But the minimum time frame in cron is 1 minitues.One
method is to keep a loop inside my script and execute it.But I would
like to know is there any other way to do the same.
So how can execute my script every 2 second.Please provide some example
code.
    </pre>
  </blockquote>
  <pre wrap=""><!---->
Good lord!  Every 2 seconds?  That's a bit extreme.

Yes, the minimum granularity for a cron job is 1 minute.  If you need
finer granularity, you need to run a script that does a sleep call:

        #!/bin/bash
        while /bin/true; do
            rsync (or whatever) >/dev/null 2>&1
            sleep 2
        done

This will do the rsync command (discarding any messages), wait for
two seconds, then repeat.

I really, REALLY recommend you do NOT do this as it can be a massive
resource hog.  If the two machines are on the same LAN, the best bet is
to share the target directory between them using NFS rather than doing
some sync job.

Alternately, look at the inotifywait stuff. You can put a watch on a
directory on the source machine and only launch the sync if a file is
written in it. You'd need to "yum install inotify-tools", and here's an
example script:

------------------------------- CUT HERE -----------------------------
#!/bin/bash
# Filename:     watchuploads.sh
# Author:       Rick Stevens, AllDigital, Inc.
# Last Edit:    29 March 2011
#
# Synopsis:
#       This script uses inotifywait to watch for newly uploaded files
#       in the /opt/uploads directory.  When something is uploaded, it
#       runs rsync to copy the file to another machine.
#               
# NOTES:
#       It's probably best to run this script in a screen(1) session or
#       via "nohup /usr/local/bin/watchuploads.sh >/dev/null 2>&1 &".
#

# Set up some variables to make life easier...
WATCHPT="/opt/uploads"                        # Directory to watch for uploads

# And away we go...
while /bin/true; do                     # Start infinite loop
    FNAME=`inotifywait -e close_write --format "%f" $WATCHPT
2>/dev/null`                                 # Watch for changes and grab
                                        # filename
    nohup rsync $WATCHPT/$FNAME remotemachine:$WATCHPT/ \
         >>/dev/null 2>&1 &            # Launch rsync
done
------------------------------- CUT HERE -----------------------------

This is FAR more efficient than doing a sleep(1) and won't put as much
of a load on the system. Look at the man pages for inotifywait(1),
inotifywatch(1) and inotify(7).
----------------------------------------------------------------------
- Rick Stevens, Systems Engineer, C2 Hosting          <a class="moz-txt-link-abbreviated" href="mailto:ricks@nerd.com">ricks@nerd.com</a> -
- AIM/Skype: therps2        ICQ: 22643734            Yahoo: origrps2 -
-                                                                    -
-       Charter Member of the International Sarcasm Society          -
-                "Yeah, like we need YOUR support!"                  -
----------------------------------------------------------------------

  </pre>
</blockquote>
<br>
<font face="monospace"></font></body>
</html>