今天用 rsync
命令同步文件到一台新vps,没想到出现了如下错误提示:
[root@web ~]# rsync -arvtP /var/www/foo cube:/var/www/bar protocol version mismatch -- is your shell clean? (see the rsync man page for an explanation) rsync error: protocol incompatibility (code 2) at compat.c(178) [sender=3.1.2]
仔细看命令参数,确认不存在错误。上网查了一下,似乎没说具体原因。于是根据错误提示,用 man
查看 rsync
文档,搜索 “mismatch”,发现如下说明:
rsync occasionally produces error messages that may seem a little cryptic. The one that seems to cause the most confusion is "protocol version mismatch -- is your shell clean?". This message is usually caused by your startup scripts or remote shell facility producing unwanted garbage on the stream that rsync is using for its transport. The way to diagnose this problem is to run your remote shell like this: ssh remotehost /bin/true > out.dat then look at out.dat. If everything is working correctly then out.dat should be a zero length file. If you are getting the above error from rsync then you will probably find that out.dat contains some text or data. Look at the contents and try to work out what is pro‐ ducing it. The most common cause is incorrectly configured shell startup scripts (such as .cshrc or .profile) that contain output statements for non-interactive logins.
看来这个错误比较常见,因此特意说明了原因及测试方法。根据文档提示,原因可能是 .bashrc 等文件中输出了内容。登录到新买的vps,打开 .bashrc,果然看到这么一段:cat /etc/motd
。不管 /etc/motd 有没有内容,这条语句都会让shell连过去时输出一行。
找到了原因,解决办法也很简单:注释掉输出语句。再回过头测试 rsync
,按照预期进行文件同步,一切正常。
其他
1. vps买自 一些VPS商家整理 中的魔方云,有这么一出真是神坑,已经向商家反馈;
2. rsync
错误之前其实已有征兆: scp
命令无法使用,结果是两个颜色控制字符。刚开始用-v选项没发现原因,不急着用就放着没管,今天才意识到原来是同一个原因;
3. 神奇的是:这个问题仅在 bash 4.4(CentOS 8默认)上出现,bash 4.2(CentOS 7默认版本)不会有这个问题。
参考
1. https://fixyacloud.wordpress.com/2020/01/26/protocol-version-mismatch-is-your-shell-clean/
原文链接:https://www.qiquanji.com/post/5024.html
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。
微信扫码关注
更新实时通知