2017-10-19 6790 views
1

这可能非常简单。我正在使用PuTTY登录到远程服务器并运行telnet 12.34.56.789 22命令来测试端口22上的TCP连接。在shell脚本中执行时,“telnet”命令失败并显示“bad port”,但在命令提示符下工作

这工作正常,当我手动键入命令时,但我有一系列目的地来检查,我认为它会最好使用这个脚本。我创建了一个非常基本的shell脚本,它只是我想要一个接一个地运行的命令列表。当我从腻子运行此脚本,我得到一个错误说

:坏端口

谁能向我解释为什么该命令的作品时,我手动输入,但会产生一个错误,当我运行脚本?

脚本:

telnet 10.52.33.46 22 
telnet 10.52.33.47 22 
telnet 10.52.33.48 22 
telnet 10.52.33.49 22 
telnet 10.52.33.50 22 
telnet 10.52.33.51 22 
telnet 10.52.33.52 22 
telnet 10.52.33.53 22 
telnet 10.52.33.54 22 
telnet 10.52.33.55 22 

Here is a screenshot of the PuTTY window with the error message. I save the above script (159999.sh) onto the host server, then run it from there.

Here is some of the commands running after I type them manually (in this case they are supposed to fail to connect)

+0

你能发布你的脚本吗? – mathB

+0

已添加到原始问题 - 为可读性添加了几行空格 – Gary

+0

*“当我运行**这些**”* - 您的意思是*“当我运行**此脚本**”*?你如何运行脚本(如果你这样做)?向我们展示截图。 –

回答

1

你的脚本文件了Windows CR/LF行结束符,而* nix系统只使用LF。

附加CR作为telnet命令的一部分,特别是作为最后一个“端口”参数的一部分。因此“坏端口”错误。

请确保您:

+0

是的,工作,谢谢! – Gary

相关问题