Scenario: An IDE is set up on a Linux desktop box, editing PHP files locally. Every time I save a file, I want this change to appear on the linux server where Apache is running. The server has ssh (and samba and nfs for that matter).

As a reference, when I edited files on Windows, I finally came over WinSCP as the exact tool I needed - WinSCP have just this feature present, with initial synch and then continuous update, using the filesystem watch service: "Keep Remote Directory up to Date".

On Linux, one could argue that sshfs could be employed to sidestep the need for synchronization entirely. On windows, a samba-share would do the same. However, I want the IDE to work with local files (on a SSD disk!), not having to go over the network to do PHP indexing and whatnots, which takes ages.

But sshfs might be a part of the solution nevertheless - so that the continuous synchronization just needed to be done between two local directories.

Any ideas or pointers?

link|improve this question
consider using the rsync tool, or sharing a folder in the webserver's document root so you could operate on the files directly under windows – hexa Aug 1 '11 at 14:43
rsync is "one go". I need continous updates, that is the entire point here - I edit a file, save it, and the product/system/idea I request would pick this save-action up and upload the new version immediately. NB: Both sides are Linux. NB2: I want to edit on local files, or else sshfs itself would cut it. – stolsvik Aug 1 '11 at 14:44
1  
Off-topic voters, this is a boundary case, but I think it falls fairly clearly under "tools commonly used by programmers" in the FAQ. – Karl Bielefeldt Aug 1 '11 at 20:44
feedback

migrated from stackoverflow.com Aug 1 '11 at 20:54

This question came from our site for professional and enthusiast programmers.

5 Answers

up vote 6 down vote accepted

You can also use inotifywait from the inotify-tools package.

inotifywait -r -m -e close_write --format '%w%f' /tmp | while read MODFILE
do
    echo need to rsync $MODFILE ...
done
link|improve this answer
2  
On the inotify-tools website, there's a pretty good example of using inotify-wait to trigger an rsync. – Karl Bielefeldt Aug 1 '11 at 20:41
I was looking for this exact thing last night! ahhh I love superuser – CenterOrbit Aug 1 '11 at 21:27
feedback

If you need to observe filesystem, then inotify is the way to do it. I would write a simple python script using pyinotify to perform sync when filesystem get changed. See documentation. You might also checkout the autosync.py for some inspiration. Have fun.

link|improve this answer
feedback

What I did once is have a bash script running ls -l in a loop (with some sleep) and comparing to the previous output. If it changed, do your synchronization.

#!/bin/bash

listcommand="ls -l $*"

newfilelist=$( $listcommand )
while true
do
   if [[ $oldfilelist != $newfilelist ]]
   then
      oldfilelist=$newfilelist
      # run your synchronization tool
   fi
   sleep 10 || exit 2 
   newfilelist=$( $listcommand )
done

Start this script in a new terminal with the file names as arguments (after putting in your synchronization tool).

(I used this to start a compilation, not to synchronize, but this would work a similar way.)

link|improve this answer
feedback

I suggest you to use an SCM System like Git or Bazaar that way you can solve two issues at the same time, including versioning control and a lot more features.

link|improve this answer
Checking in and checking out for every edit of every angle-bracket is out of the question - and wouldn't solve the problem I was stating, namely automatically transferring such edits. I already use a SCM, of course! ;-) – stolsvik Aug 3 '11 at 17:57
feedback

Much more simple approach:

Export your /var/www with samba (or nfs) and work on the files directly on the server.

Another solution: most IDE's allow various deployment configuration - check if there is one that suits you.

Or set a Source Code Management system like Git, Bazaar, etc.

Good luck !!

link|improve this answer
Thanks for answering. However, I specifically excluded this very approach in the question. – stolsvik Aug 3 '11 at 17:55
feedback

Your Answer

 
or
required, but never shown

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