在shell脚本中执行时,“telnet”命令失败并显示“bad port”,但在命令提示符下工作
问题描述:
这可能非常简单。我正在使用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
答
你的脚本文件了Windows CR/LF行结束符,而* nix系统只使用LF。
附加CR作为telnet
命令的一部分,特别是作为最后一个“端口”参数的一部分。因此“坏端口”错误。
请确保您:
- 保存使用脚本*上传之前或
- nix的行结束符使用文本方式转让或
- convert the file on the server上传脚本。
+0
是的,工作,谢谢! – Gary
你能发布你的脚本吗? – mathB
已添加到原始问题 - 为可读性添加了几行空格 – Gary
*“当我运行**这些**”* - 您的意思是*“当我运行**此脚本**”*?你如何运行脚本(如果你这样做)?向我们展示截图。 –