あいつの日誌β

働きながら旅しています。

備忘録: リモートホストとローカルホストを同期させるアレ

以下備忘録

% cat ~/script/ignore
#image
#+ app/webroot/images/common/
#- app/webroot/images/*
 
#config
#- app/Config/bootstrap.php
#- app/Config/database.php
 
#basic
- **/*.jpg
- .DS_Store
- .git/
- .gitignore
% cat ~/script/rsync.sh
if [ $1 != 'app' -a $1 != 'lib' ]; then
    echo "error: invalid param '$1'";
    exit 1
fi

cd $HOME/script/
sync -av --exclude-from="ignore" ~/workspace/projectName/$1 test.example.com:/var/www/html/your-test/

このままだと ssh で都度パスフレーズ聞かれるので以下を実行

% ssh-agent
% ssh-add ~/.ssh/keys/id_rsa 

ファイルの変更を監視するスクリプト

#!/usr/bin/env perl
use strict;
use warnings;
use Filesys::Notify::Simple;

my $dir = '/Users/okamuuuu/projectName';

my $watcher = Filesys::Notify::Simple->new(
    [ "$dir/app/", "$dir/lib/" ] );

while(1) {
    $watcher->wait(sub {
        for my $event (@_) {
            # full path of the file updated
            warn $event->{path};
            if ($event->{path} =~ m!$dir/([^/]*)/!) {
                warn `rsync.sh $1`;
            }
        }
    });
}

監視開始

% perl watch.pl