对于ssh连接,有一种简单的方法可以测试您的shell是否干净:从ssh连接运行命令,而不是启动交互式shell。该false
命令将立即终止而不产生任何输出,因此是一个很好的测试:
bash$ ssh remotehost false
Enter passphrase for key '/home/user/.ssh/my_private_key':
bash$
如果该命令行产生任何输出,则应怪罪您的启动脚本之一:
bash$ ssh remotehost false
Enter passphrase for key '/home/user/.ssh/my_private_key':
Welcome to RemoteHost!
This system is company property and is provided for authorized use only,
as set forth in applicable written policies. Unauthorized use is prohibited
and may be subject to discipline, civil suit and criminal prosecution.
Welcome back - You last logged in 16 days ago...
bash$
检查是否收到此错误的另一件事是ssh是否安装了rsync并可以找到它:
bash$ ssh remotehost "rsync --version"
Enter passphrase for key '/home/user/.ssh/my_private_key':
rsync version 3.0.9 protocol version 30
Copyright (C) 1996-2011 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
append, ACLs, xattrs, iconv, symtimes
rsync comes with ABSOLUTELY NO WARRANTY. This is free software, and you
are welcome to redistribute it under certain conditions. See the GNU
General Public Licence for details.
bash$
如果rsync不在路径中,您将看到类似以下内容:
bash$ ssh remotehost "rsync --version"
Enter passphrase for key '/home/user/.ssh/my_private_key':
bash: rsync: command not found
bash$
您可以通过安装rsync来解决此问题,或者将其安装到rsync命令行中(如果已安装但在不寻常的位置):
rsync -avvvz -e "ssh -i /home/thisuser/cron/thishost-rsync-key" \
--rsync-path="/usr/local/bin/rsync" \
remoteuser@remotehost:/remote/dir /this/dir/
ESC x shell
和doexport TERM=xterm; ssh remotehost ls
。如果出现任何控制字符或其他虚假输出,这就是您必须寻找的内容。