シェルスクリプト内での rsync に ssh 鍵を指定する

rsync を ssh でするとき、普通のコマンドラインなら

$ rsync -e "ssh -i /path/to/ssh_key" -avz -p -o \
--delete remoteuser@hostname:/path/to/remote/file /path/to/local_save/file

てな感じにするけれど、
シェルスクリプト内だと、”ssh -i /path/to/ssh_key” の部分が指定を見てくれないのです。何かやり方があるのかな??

でも、環境変数 RSYNC_RSH に ssh の鍵指定をしてやればOK。
man page にこんなことが書いてあります。

You  can  also choose the remote shell program using the RSYNC_RSH
environment variable, which accepts the same range  of  values  as
-e.

なので、こういう風にすればOK。

RSYNC_RSH="ssh -i /path/to/ssh_key"
# rsync -avz -p -o --delete remoteuser@hostname:/path/to/remote/file /path/to/local_save/file

2007年 12月 25日 | Posted in Linux
タグ:
コメントは終了しています。