Find the answer to your Linux question:
Results 1 to 5 of 5
I want to connect to a remote host using telnet there is no username/password verification just Code: telnet remotehost then I need to input some commands for initialization and then ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    May 2012
    Posts
    85

    How to run scripts within a telnet session?


    I want to connect to a remote host using telnet
    there is no username/password verification
    just
    Code:
        telnet remotehost
    then I need to input some commands for initialization

    and then I need to repeat the following commands:
    Code:
        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:
    Code:
        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!

  2. #2
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,378
    It is possible via expect.
    However, to me a more stable Implementation seems to be a cronjob, that downloads that args list
    and processes it.
    You dont need to keep a connection open, you can more easily react on errors, etc
    You must always face the curtain with a bow.

  3. #3
    Just Joined!
    Join Date
    May 2012
    Posts
    85
    I don't get your point,
    there is no need to downloads an args list, it is in my local computer
    I need to keep the connection open, I need to test the args on the remote mach

  4. #4
    Trusted Penguin Irithori's Avatar
    Join Date
    May 2009
    Location
    Munich
    Posts
    3,378
    The point is, if the processing takes a while then the telnet connection could be interrupted.
    Think: TimeOuts, someone tripping over a network wire etc.

    On the other hand, if the remote machine downloads the args list, then a) this doesnt take long and b) it can be checked for errors. (ie: if the wget fails, abort with an error)
    Once the args list is on the remote machine, it can then process it. Decoupled from your local box.
    The output of such a cronjob would then be in a logfile and/or textfile that you can get from the local box again.

    But it really depends on the usecase. If you want to do it via telnet, then just wrap it in an expect script.
    You must always face the curtain with a bow.

  5. #5
    Just Joined!
    Join Date
    May 2012
    Posts
    85
    I can't control the remote machine, so i can't put the arg list on the remote machine

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •