LoginSignup
2
3

More than 5 years have passed since last update.

ファイルの変更を検知してscpを実行するコマンド

Last updated at Posted at 2016-07-12

ローカルで更新したファイルをサーバにアップロードしたい場合に使うコマンド。ローカルはmacOSを想定。

fswatchをインストールしておく

Linuxにはinotifywaitがあるが、macOSにはそれがないため、それ相当のツールであるfswatchをインストールする。

brew install fswatch

ファイルの変更を検知してscpを実行するコマンド

$ dist="foo@remote_server:path" &&
  fswatch -0 . | {
    while read -d "" file
    do 
        pwd="$(pwd)/"
        src="${file:${#pwd}}"
        scp $src $dist
    done
}

実行例

$ dist="pi@10.0.1.43:" &&
fswatch -0 . | {
    while read -d "" file
    do
        pwd="$(pwd)/"
        src="${file:${#pwd}}"
        scp $src $dist
    done
}
test.py                                                                             100% 3749     3.7KB/s   00:00
test.py                                                                             100% 3746     3.7KB/s   00:00
test.py                                                                             100% 3746     3.7KB/s   00:00
test.py                                                                             100% 3759     3.7KB/s   00:00
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3