View Single Post
Old 06-23-08, 08:41 AM   #3
wnd
Nerd, Geek, Freak
 
wnd's Avatar
 
Join Date: Sep 2005
Location: Finland
Posts: 703
Default Re: Need to make a super simple program

Code:
#! /bin/sh

while true; do
        cp -dpR source destination
        sleep 2
done
Especially if you only need to do this temporarily, a simple script should suffice just fine. Note that if you're processing large number of files, two second interval could prove to be a bit too short.

If you want to make copying smarter (only copy the files when they're changed), use rsync.

Code:
#! /bin/sh

while true; do
        rsync -u source destination
        sleep 2
done
If you want copying to /start/ every N seconds, you could replace the main loop with something like the following. It will /not/ handle fractions of seconds well so it's not very accurate.

Code:
n=10 # start copy every N seconds
before=$(date +%s)
while true; do
        # copying happens here
        after=$(date +%s)
        sleep $(( n - after + before ))
        before=after # save one call to date
done
If you're running Windows you can install Cygwin, or rewrite the script as batch-program.
__________________
web | cat

Christianity, noun: The belief that a cosmic Jewish Zombie who was his own father can make you live forever if you symbolically eat his flesh and telepathically tell him you accept him as your master, so he can remove an evil force from your soul that is present in humanity because a rib-woman was convinced by a talking snake to eat from a magical tree. [mad.frog]
wnd is offline   Reply With Quote