【问题标题】:how to run scripts within a telnet session如何在 telnet 会话中运行脚本
【发布时间】:2012-12-07 03:56:24
【问题描述】:

我想使用 telnet 连接到远程主机 没有用户名/密码验证 只是

telnet remotehost

那我需要输入一些初始化命令

然后我需要重复以下命令:

cmd argument

参数是从本地文件中读取的,在这个文件中有很多行,每一行都是一个参数 运行一个“cmd参数”后,远程主机会输出一些结果 它可能会输出带有字符串“OK”的行 或输出多行,其中一行带有字符串“ERROR” 我需要根据结果做一些事情。

基本上,脚本是这样的:

initialization_cmd  #some initial comands
while read line
do    
  cmd $line
  #here the remote host will output results, how can I put the results into a variable?
  # here I want to judge the results, like
  if $results contain "OK";then
       echo $line >>good_result_log
  else
       echo $line >> bad_result_log
  fi     
done < local_file

 the good_result_log and bad_result_log are local files

有没有可能?谢谢!

【问题讨论】:

  • 我建议您为bashksh 添加标签,以提高您问题的读者群。请注意,telnet 标签只有 19 个关注者。除非 bash4 中有支持更好的命名管道式通信的新功能,正如@cmh 建议的那样,expect 是解决此类问题的最佳选择。祝你好运。

标签: bash shell telnet


【解决方案1】:

这不起作用,因为 echo 将输出到 tty 的标准输出,而不是 telnet 进程的标准输入。

我建议为此任务编写一个expect 脚本。也许你可以改写this之类的东西。

【讨论】:

    【解决方案2】:

    这个问题同时在至少四个不同的论坛上提出。不知道这种创业能赚多少分,这里有答案链接:

    【讨论】:

      猜你喜欢
      • 2010-10-17
      • 2017-07-09
      • 2017-08-29
      • 1970-01-01
      • 2011-07-17
      • 2016-09-18
      • 2014-01-21
      • 2019-08-22
      • 2014-03-15
      相关资源
      最近更新 更多