rsyncで「bash: line 1: rsync: command not found」が発生

rsyncを行うと「bash: line 1: rsync: command not found」になりました。

原因を調査すると、相手方のサーバにrsyncがインストールされていなかったことが原因でしたという話です。

原因が分かるまでちょっと時間が掛ったので、今後忘れないようにメモしておきます。

rsyncで「bash: line 1: rsync: command not found」

rsyncを実行したら「bash: line 1: rsync: command not found」が発生しました。

$ rsync -az -e 'ssh -p 10022 -i ~/.ssh/xxxxxx' tamohiko@xxx.xxx.xxx.xxx:/home/tamohiko/photo_202404.tar.gz .
bash: line 1: rsync: command not found
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(231) [Receiver=3.2.7]

※一部情報をマスクしています。

原因の調査

rsyncの確認

「command not found」と言っているので、rsyncコマンドが無いのかなと思ったので「which」コマンドで確認します。

$ which rsync
/usr/bin/rsync

ちゃんと存在していることが確認できました。

rsyncの詳細ログを表示させてみる

rsyncは存在しているのに「command not found」とはどう言うことなのかよく分からなかったので、「vv」オプションを追加して詳しい情報を確認してみることにしました。

$ rsync -azvv -e 'ssh -p 10022 -i ~/.ssh/xxxxx' tamohiko@xxx.xxx.xxx.xxx:/home/tamohiko/photo_202404.tar.gz .
opening connection using: ssh -p 10022 -i "~/.ssh/xxxxx" -l tamohiko xxx.xxx.xxx.xxx rsync --server --sender -vvlogDtprze.iLsfxCIvu . /home/tamohiko/photo_202404.tar.gz  (14 args)
bash: line 1: rsync: command not found
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: error in rsync protocol data stream (code 12) at io.c(231) [Receiver=3.2.7]

「opening connection」と表示されているので、sshでの接続は行われていてその後に「bash: line 1: rsync: command not found」と表示されているため、相手側の問題なのかなと思い確認してみることしました。

相手側サーバでrsyncを確認

相手側サーバでrsyncを確認してみると、インストールされていなことが分かりました。

$ rsync
-bash: rsync: command not found

rsyncをインストールします。

# dnf install rsync

rsyncの再実行

相手側にrsyncをインストールした後に、再度rsyncでデータ転送を行ってみます。

$ rsync -azvv -e 'ssh -p 10022 -i ~/.ssh/xxxxx' tamohiko@xxx.xxx.xxx.xxx:/home/tamohiko/photo_202404.tar.gz .
opening connection using: ssh -p 10022 -i "~/.ssh/xxxxx" -l tamohiko xxx.xxx.xxx.xxx rsync --server --sender -vvlogDtprze.iLsfxCIvu . /home/tamohiko/photo_202404.tar.gz  (14 args)
receiving incremental file list
delta-transmission enabled
photo_202404.tar.gz
total: matches=7384  hash_hits=7384  false_alarms=0 data=0

sent 51,731 bytes  received 188 bytes  20,767.60 bytes/sec
total size is 54,460,831  speedup is 1,048.96

今回は無事にrsyncでデータ転送が行われました。

今回の原因

今回rsync実行時に「bash: line 1: rsync: command not found」が発生た原因は、相手方にrsyncがインストールされていなかったためでした。

「command not found」とメッセージが表示されていたのですが、rsyncは全部のサーバに初期でインストールされていると思い込んでいたので、すぐに原因に思い当たらず突き止めるまでに時間が少し掛ってしまいました。

思い込みには気をつけなくてはいけませんね。

今回の相手側のサーバはAlmaLinux9だったのですが、rsyncって最近ははじめからインストールされていないのですね。

最近はUbuntuを使うことが多いのですが、こちらは最初からインストールされていたような気がします。

もしかして自分でインストールしたの忘れているだけ???

コメント

タイトルとURLをコピーしました