当我尝试将FTP(使用WinSCP)保护到我的CentOS 6.4框时,系统会提示一条消息,指出:
Received too large (168438314 B) SFTP packet. Max supported packet size is 1024000 B. This error is typically caused by message printed from startup script (like profile). The message may start with ""\n\n**"" Cannot initialize SFTP protocol. Is the host running an SFTP server
这似乎是由我的/etc/profile.d/custom.sh脚本在login过程中运行引起的。 其设置输出一个欢迎消息,以及一个系统摘要(CPU /内存/磁盘使用情况)。
我真的需要在login到本地控制台或通过SSHlogin时运行custom.sh脚本。 但是,我不希望它login到安全FTP(SFTP)时运行。
有什么方法可以configuration它通过安全FTPlogin时不运行?
或者,如果我不能阻止它从运行有一种方法,我可以检测到它在一个安全的FTPlogin运行,不输出任何东西。 所以在伪代码类似于:
如果通过安全FTPlogin,则不输出任何内容,如果通过SSH或Local Console输出消息(系统统计信息)login。
谢谢! 布拉德
更新 – 这里有支持这个问题的文档: http : //winscp.net/eng/docs/requirements#remote_environment
build议是检测会话是否是交互式的。 我试图通过添加以下到我的custom.sh的顶部,但它仍然不工作:
if [ -z $PS1 ]; then ### if [ -v PS1 ] # On Bash 4.2+ ... # non-interactive return fi
然后我的脚本的其余部分运行输出MOTD。
应该将SecureFTP检测为非交互式或交互式? 如果它是非交互的,为什么当我尝试通过Secure FTPlogin时,上面的代码不存在?
也许检查fd'0'的标准方法?
if [ -t 0 ]; then # do stuff fi