Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've got a directory called "secure" that I mount on my laptop via sshfs whenever the server is in reach.

While this server is in reach I want to keep it in two-way sync with a directory called "sync".

The "secure" directory is mounted with pam_mount at login and unmounted at logout. I have setup pam_script to create a symbolic link to "sync" when the mount fails and to remove the link on unmount.

In my first attempt was to run unison with pam_script:

#!/bin/bash

#pam_script_ses_open (runs at the start of a session)

home=`eval echo ~$PAM_USER`
secure=$home/secure
sync=$home/sync

if mount|grep "$secure"; then
    echo Synchronizing with server $sync : $secure
    unison "file://$sync" "file://$secure"
else
    ln -s "$sync" "$secure"
fi

And for end of session:

#!/bin/bash

userid=$PAM_USER
home=`eval echo ~$userid`
secure=$home/secure
sync=$home/sync

if mount|grep "$secure"; then
        echo Synchronizing with server
        unison "file://$sync" "file://$secure"
else
        rm "$secure"
fi

Both these scripts run under root.

At logout the two directories synchronize just fine.

At login however I get the following error message:

Synchronizing with server /home/users/user/sync : /home/users/user/secure

Contacting server...

Fatal error: Wrong number of roots: 2 expected, but 4 provided (ssh://user@server/, /home/users/user, file:///home/users/user/secure, file:///home/users/user/sync)

(Maybe you specified roots both on the command line and in the profile?)

I have verified that no ".unison" directory exists in any users home directory and did apt-get purge unison followed by an apt-get install unison.

I am not entirely happy about using unison in this way (even if it did work) because it would only synchronize at login and logout. It would not be a live synchronization.

How can I get sshfs or fstab to start a live synchronization whenever the directory is mounted or if that is not possible, why is unison failing in my current setup?

I am looking for a clean and robust solution.

share|improve this question
    
@LuisAlvarado my setup is described here: help.ubuntu.com/community/SingleSignOn#Shared_Files. It is not very uncommon that people have laptops and would like to sync those mounts for when they are on the move. Somebody has also market it as a favourite. All of this kinda proves you wrong. –  d_inevitable Apr 13 '13 at 21:10
    
Hi @d_inevitable can you provide the answer to the question in this site. –  Luis Alvarado Apr 13 '13 at 23:50
    
@LuisAlvarado unfortunately I haven't solved that yet. –  d_inevitable Apr 14 '13 at 0:01
    
@LuisAlvarado, sorry I have probably caused some confusion. The link ive posted Is not answering the question, but it brings one to a setup in which you mount a remote filesystem at login. My point was that when somebody sets that up on a mobile workstation such as a laptop it desirable to somehow cache that filesystem locally. And this is what I am trying to achieve and this is what the question is about. So it will be useful to anybody who set up the system as described on that link, but has a laptop that is not always online. –  d_inevitable Apr 14 '13 at 0:06
    
Well the fact that you took your time to explain this shows you are committed to the question which I wrongly closed. Thanks again for the information and will leave the question opened for anybody to help you in this case (Which also intrigues me). –  Luis Alvarado Apr 14 '13 at 0:46

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.