How to run scripts within a telnet session?

Posted by wenzi on Super User See other posts from Super User or by wenzi
Published on 2012-12-19T21:09:10Z Indexed on 2012/12/19 23:05 UTC
Read the original article Hit count: 187

Filed under:
|
|

I want to connect to a remote host using telnet there is no username/password verification just

telnet remotehost

then I need to input some commands for initialization

and then I need to repeat the following commands:

cmd argument

argument is read from a local file, in this file there are many lines, each line is a argument and after runing one "cmd argument", the remote host will output some results it may output a line with string "OK" or output many lines, one of which is with string "ERROR" and I need to do something according to the results.

basically, the script is like:

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

is it possible or not? thanks!

NOTE: I can't control B, I can only run initial cmds and cmd $line on B

© Super User or respective owner

Related posts about bash

Related posts about script