Welcome to the Linux Foundation Forum!

Telnet logging

Hello everyone. I have a script that telnets into a linux workstation and restarts a service, while logging the session to a file. I'm kind of new to linux so when I was using windows I would capture something like

windows cli: telnet xxx.xxx.xxx.xxx -f c:/capture.log

...

[me@remote]# /sbin/service dhcpd restart

Shutting down dhcpd: OK]

Starting dhcpd: OK]

Now when using the linux telnet client I capture something like

[me@local]# telnet xxx.xxx.xxx.xxx | tee -a /users/me/capture.log

...

[me@remote]# /sbin/service dhcpd restart

Shutting down dhcpd: [60G[ [0;32mOK[0;39m ]

Starting dhcpd: [60G[ [0;32mOK[0;39m ]

It looks like the telnet session is passing control characters or something like that to the log file, which messes up some scripts that check whether the service was succesfully restarted.

I've already tried playing around with the telnet mode (line vrs char) with no effect. Any ideas on how to get the log with just plain text?

Thanks for any advice and sorry if I posted in the wrong place.

Comments

  • marc
    marc Posts: 647
    Elyas_CR wrote:
    Hello everyone. I have a script that telnets into a linux workstation and restarts a service, while logging the session to a file. I'm kind of new to linux so when I was using windows I would capture something like

    windows cli: telnet xxx.xxx.xxx.xxx -f c:/capture.log
    ...
    [me@remote]# /sbin/service dhcpd restart
    Shutting down dhcpd: OK]
    Starting dhcpd: OK]

    Now when using the linux telnet client I capture something like

    [me@local]# telnet xxx.xxx.xxx.xxx | tee -a /users/me/capture.log
    ...
    [me@remote]# /sbin/service dhcpd restart
    Shutting down dhcpd: [60G[ [0;32mOK[0;39m ]
    Starting dhcpd: [60G[ [0;32mOK[0;39m ]

    It looks like the telnet session is passing control characters or something like that to the log file, which messes up some scripts that check whether the service was succesfully restarted.
    I've already tried playing around with the telnet mode (line vrs char) with no effect. Any ideas on how to get the log with just plain text?

    Thanks for any advice and sorry if I posted in the wrong place.

    [ rant on]
    TELNET MUST DIE
    [rant off]
    [me@local]# telnet xxx.xxx.xxx.xxx | tee -a /users/me/capture.log
    

    Why don't you try with:
    [me@local]# telnet xxx.xxx.xxx.xxx >> /users/me/capture.log
    

    Or if you insist to use tee, try with the -i option:
    [me@local]# telnet xxx.xxx.xxx.xxx | tee -a  -i /users/me/capture.log
    

    Regards

Categories

Upcoming Training