4

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.

d_inevitable
  • 1,882
  • 3
  • 22
  • 35
  • @LuisAlvarado my setup is described here: https://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 00: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 00: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 00:46
  • @LuisAlvarado I would like to VTC as not reproducible but I see you have already closed it and reopened it. The Ubuntu version being used back in 2012 is EOL and the question appears to be abandoned as it has never been "bumped" by edits from OP. Do you think VTC is appropriate here? Thanks :) – WinEunuuchs2Unix Jul 18 '17 at 00:06

0 Answers0