Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question
up vote 1 down vote accepted

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.

share|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
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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