【shell】在while Read中ssh提前中断解决办法

【shell】在while Read中ssh提前中断解决办法

时间:2013-08-07 02:08:14      作者:beebol      标签: shell ssh while read      分类: Shell

 在写while read循环时,只执行到第一行就中断了,这是为什么呢?

while read line

do ssh xxxx  done  <file 问题原因是由于: ssh需要用到stdin,当ssh推出,"顺便"就把当前stdin中断了.既然stdin中断,自然read也读不进来新数据,while read就断了,只要在ssh连接的时候加上一个-n参数就可以了。具体写法如下: cat file | while read line do ssh -n xxxx done

时间:2013-08-07 02:08:14      作者:beebol      标签: shell ssh while read      分类: Shell
  • 分享到:
  • 微博
  • QQ空间
  • 腾讯微博
  • 微信

Copyright © 2015 Gitblog | Proudly powered by Gitblog.