为什么找不到 rsync?

elb*_*rna 25 path rsync

rsync -avP /home/user/.profile hpux3:/home/user/.profile
bash: rsync: command not found
Run Code Online (Sandbox Code Playgroud)

如果我对 hpux3 机器做了 ssh

rsync  
version 3.1.1  protocol version 31
Copyright (C) 1996-2014 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
output truncated
Run Code Online (Sandbox Code Playgroud)

我已经设置PATH$HOME/.profile$HOME/.bashrc。我应该在/etc/profile文件中设置它吗?

Gil*_*il' 30

.profile当你登录交互是只读的。当 rsync 连接到另一台机器执行命令时,/etc/profile并且~/.profile不被读取。

如果您的登录 shell 是 bash,则~/.bashrc可能会被读取(这是 bash 的一个怪癖——~/.bashrc由非登录交互式 shell 读取,在某些情况下由登录非交互式 shell 读取)。但这并不适用于所有版本的 bash。

使 rsync 工作的最简单方法可能是传递--rsync-path选项,例如

rsync --rsync-path=/home/elbarna/bin/rsync -avP /home/user/.profile hpux3:/home/user/.profile
Run Code Online (Sandbox Code Playgroud)

如果您使用基于密钥的身份验证通过 SSH 登录,则可以PATH通过~/.ssh/authorized_keys. 有关使用密钥通过 SSH 登录时如何安排加载的说明,请参阅ssh 上的 sh 启动文件.profile

  • 注意: `--rsync-path` 用于设置 **remote** 计算机上 `rsync` 的路径。(乍一看,我想知道如何在同一台机器上启动 `rsync` 时指定到 `rsync` 的路径) (12认同)

小智 16

如果远程端未安装 rsync,则尝试将文件和目录从远程计算机同步到本地系统时也会发生此错误。

rsync -zarvh oem@172.20.0.12:/var/www/html/release /var/www/html/release
bash: rsync: command not found
Run Code Online (Sandbox Code Playgroud)

在远程端安装 rsync 将解决这种情况