小编wen*_*nzi的帖子

如何在 telnet 会话中运行脚本?

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

telnet remotehost
Run Code Online (Sandbox Code Playgroud)

然后我需要输入一些命令进行初始化

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

cmd argument
Run Code Online (Sandbox Code Playgroud)

参数是从本地文件中读取的,在这个文件中有很多行,每一行是一个参数,运行一个“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
Run Code Online (Sandbox Code Playgroud)

有可能吗?谢谢!

注意:我无法控制 B,我只能在 B 上运行初始 cmds 和 cmd $line

telnet script bash

5
推荐指数
1
解决办法
1万
查看次数

标签 统计

bash ×1

script ×1

telnet ×1