General discussion

  • Creator
    Topic
  • #2108579

    Telnet in background

    Locked

    by mis ·

    We have a monitoring device that acts as a passthrough for a serial connection to a telnet session. We capture the incoming serial data to a file by opening a telnet session to the device and redirecting telnet’s output to a file. I know, it’s an ugly hack, but believe me we have tried many solutions and this is by far the most reliable.

    Unfortunately, reliable does not mean effortless. Every day, someone has to close the telnet capture session, import the data, and start a new capture. All this from the console.

    I am trying to semiautomate this by creating a batch file that will 1) kill the existing process, 2) start a new capture, and 3) write the process number of the new capture to a file, so the next time around it can tell which process to kill. Essentially, it says:

    kill -s SIGTERM `cat .capturepid`
    nohup telnet [address] [port] > [file] &
    echo $! > .capturepid

    When I try this from the command line, I get a message ‘Connection closed by foreign host’.

    Iwant to be able to run this from cron, and never again have to go to the machine to cycle the capture. But there seems to be some difficulty keeping the telnet session live in the background. Why would this be?

    Any and all ideas would be appreciated!

All Comments

  • Author
    Replies
    • #3840814

      Telnet in background

      by hasse mcse/brainbench ·

      In reply to Telnet in background

      Hi!

      I don’t know why you can’t put telnet into background, but could you do it like this instead.

      Create a special user that does nothing else but run the telnet session for capturing data.

      Then run a cron job as that user that starts say 10:00 in the morning or something. At 11:00 or whener you start a cronjob as root that does this:
      kill -s 9 `ps -ef | grep [special username] | awk ‘{ print $2 }’`

      This might solve ur problem, this way you wouldn’t need to put the telnet session into the background.

      /Hasse

      • #3629600

        Telnet in background

        by mis ·

        In reply to Telnet in background

        The question was auto-closed by TechRepublic

    • #3633332

      Telnet in background

      by estebandelatorre ·

      In reply to Telnet in background

      Agree with answer 1, points for him

      • #3629601

        Telnet in background

        by mis ·

        In reply to Telnet in background

        The question was auto-closed by TechRepublic

    • #3629599

      Telnet in background

      by mis ·

      In reply to Telnet in background

      This question was auto closed due to inactivity

Viewing 2 reply threads