I'm running Debian 6 64bit.

What I'm trying to do is run Unison on startup to constantly monitor files on the LAMP server I have running on my VM and sync that with the VM Shared folder.

while true
    unison -batch -owner -group /folder1/ /folder2/
    sleep 10

Now, I can get this script to run at startup... but the problem is that it hangs. Even if I use nohup, it hangs at the nohup dialog.

Also, if there is a way I can use nohup I'd really rather it not log anything at all. However, I can't find this option in either nohup or unison documentation. I may be overlooking it, but I can't find it.

I'm sure there is a way to link Apache to another folder and just use that... but I still want to know how to do this because I could use it in different contexts as well.

Thank you


Why not to point Apache to your shared folder on VM in the first place? This is as simple as to add/change one file for your virtualhost (I believe you've done this anyway). This will let you not to wait 5-10 seconds while your server document root is being updated.

However what you actually ask is a periodically running some command, so in the end you just need a cron job. This answer may be helpful for you.

So you just add to your crontab file:

* * * * * unison -batch -owner -group /folder1/ /folder2/ >/dev/null 2>&1
* * * * * sleep 10; unison -batch -owner -group /folder1/ /folder2/ >/dev/null 2>&1
* * * * * sleep 20; unison -batch -owner -group /folder1/ /folder2/ >/dev/null 2>&1
* * * * * sleep 30; unison -batch -owner -group /folder1/ /folder2/ >/dev/null 2>&1
* * * * * sleep 40; unison -batch -owner -group /folder1/ /folder2/ >/dev/null 2>&1
* * * * * sleep 50; unison -batch -owner -group /folder1/ /folder2/ >/dev/null 2>&1

The >/dev/null 2>&1 means to redirect stdout and stderr output i.e. remove all logging.

| improve this answer | |

There is a built in -repeat flag, which you can give a number of seconds that unison should wait between executions. See the manual.

unison -repeat 10 -batch -owner -group /folder1/ /folder2/
| improve this answer | |
vi /etc/sysconfig/unison.env

add export HOME=/path/to/home(for example: export HOME=/home/user1)

vi /etc/init.d/unison

add these lines:

# chkconfig: 2345 20 80
# description: unison service

# add this line to avoid `Fatal error: exception Util.Fatal("Environment variable HOME not found")`
. /etc/sysconfig/unison.env
case $1 in
        unison -batch -owner -group /folder1/ /folder2/ &

        ps aux | grep -v grep | grep unison | awk '{print $2}' | xargs kill -9

        echo "Usage: service unison {start|stop}"

config startup

chkconfig unison on
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.