免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3815 | 回复: 6
打印 上一主题 下一主题

[系统管理] 为何.bashrc中加上echo,sftp就坏了? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-11-25 00:08 |只看该作者 |倒序浏览
本帖最后由 aleng 于 2010-11-25 14:51 编辑

我是可以用root,通过ssh,sftp连接到我的服务器的,但是呢,最近sftp连不上了,但是ssh还是好的。

经过我的排查,我发现,不能在。bashrc中加如任何echo 语句,去掉echo语句立马就好,

服务器是centos和fc,用了2种sftp客户端软件都是这样。这两种客户端软件都不是putty开发的。

真是奇了 ,谁帮我试试,你那是不是这样。

论坛徽章:
0
2 [报告]
发表于 2010-11-25 10:44 |只看该作者
见putty的FAQ
A.7.6 When attempting a file transfer, either PSCP or PSFTP says ‘Out of memory’ and dies.

This is almost always caused by your login scripts on the server generating output. PSCP or PSFTP will receive that output when they were expecting to see the start of a file transfer protocol, and they will attempt to interpret the output as file-transfer protocol. This will usually lead to an ‘out of memory’ error for much the same reasons as given in question A.7.5.

This is a setup problem in your account on your server, not a PSCP/PSFTP bug. Your login scripts should never generate output during non-interactive sessions; secure file transfer is not the only form of remote access that will break if they do.

On Unix, a simple fix is to ensure that all the parts of your login script that might generate output are in .profile (if you use a Bourne shell derivative) or .login (if you use a C shell). Putting them in more general files such as .bashrc or .cshrc is liable to lead to problems.

http://www.chiark.greenend.org.uk/~sgtatham/putty/faq.html

论坛徽章:
0
3 [报告]
发表于 2012-08-17 16:41 |只看该作者
今天我也遇到差不多的情况了。
我在bashrc中加入了一个df -h用来每次登录看硬盘大小(个人需要,因为硬盘是作数据交互的,但用处不大,就这么凑合了),结果用FILEZILLA登录SFTP,提示out of memory。
后来改在在crontab中把df -h写到/tmp/df_h中,在bashrc中用cat来显示也不行。
最后想起昨天搞screen时提示的:Cannot open your terminal '/dev/pts/1' - please check,这个错误让我想到了SFTP登录和普通登录的区别,然后把bashrc中的改成下面这样:
if [ ! '' = `tty |grep dev` ]; then df -h; fi
是很无语的作法,BUT IT WORKS WELL!

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
4 [报告]
发表于 2012-08-17 17:23 |只看该作者
你会发现,如果用rsync传文件的话也会报错的,所以不能在bash_profile和bashrc里面增加echo之类的命令,你要是想加点内容,可以往/etc/motd里面加

论坛徽章:
15
2015年辞旧岁徽章
日期:2015-03-03 16:54:15双鱼座
日期:2015-01-15 17:29:44午马
日期:2015-01-06 17:06:51子鼠
日期:2014-11-24 10:11:13寅虎
日期:2014-08-18 07:10:55酉鸡
日期:2014-04-02 12:24:51双子座
日期:2014-04-02 12:19:44天秤座
日期:2014-03-17 11:43:36亥猪
日期:2014-03-13 08:13:51未羊
日期:2014-03-11 12:42:03白羊座
日期:2013-11-20 10:15:18CU大牛徽章
日期:2013-04-17 11:48:45
5 [报告]
发表于 2012-08-20 09:25 |只看该作者
zhsh87 发表于 2012-08-17 19:23
你会发现,如果用rsync传文件的话也会报错的,所以不能在bash_profile和bashrc里面增加echo之类的命令,你要 ...

/etc/motd 是个全局的设置。

lkk2003rty 的回复中,已经提到了,针对个人的设置,可以加在 .profile 或者 .login 里。

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
6 [报告]
发表于 2012-08-20 09:58 |只看该作者
.profile最好别加echo,可能还会引起传文件报错的问题,.login到没试过,有兴趣可以试试

论坛徽章:
0
7 [报告]
发表于 2012-08-20 13:55 |只看该作者
把echo写入一个shell脚本,在.profile调用这个脚本试试。
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP