Find the answer to your Linux question:
Results 1 to 6 of 6

Thread: Telnet script

Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Telnet script

    I have a linux device connected to my pc in local network. That device doesn't have cron implemented, and I need to run some script on it every morning. So I thought maybe I could use linux on pc and schedule a cron which would connect to this device and run this script.
    So I would need the script to login to telnet to something like
    using username root,password password and execute /var/script/
    Not sure how exactly to pull it off, but I am pretty sure it is possible. I've seen something with using echo to enter login info but I am not sure what exact syntax should be.

  2. #2
    The only way I can think to do this, coming from my fairly limited experience mind you, would be to write a program that initializes a connection to and then waits for the server to output back to your program, then replies as necessary with login information, then opens the file and sends it line by line, but Im a little hazy as to what exactly you are going to be doing with it so I cant really say for sure, but that's my best suggestion.

    If you need help writing a program to handle that connection that is definitely something I can help you with, just let me know.

  3. #3
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Saint Paul, MN, USA / CentOS, Debian, Slackware, {Free, Open, Net}BSD, Solaris
    Expect is a program that "talks" to other interactive programs accord-
    ing to a script. Following the script, Expect knows what can be
    expected from a program and what the correct response should be. An
    interpreted language provides branching and high-level control struc-
    tures to direct the dialogue. In addition, the user can take control
    and interact directly when desired, afterward returning control to the

    -- excerpt from man expect, q.v.
    cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  4. $spacer_open
  5. #4
    @file37, I need it to do exactly what I mentioned in first post. Telnet to local machine, enter root's login detailes, run one script and quit.

    @drl, thx I'll check out expect.

  6. #5
    I would also use expect to script a ssh/telnet session but it can be done
    like so:

    ./ | telnet

    echo open $host $port
    sleep 1
    echo $login
    sleep 1
    echo $passwd
    sleep 1
    echo $cmd
    sleep 1
    echo exit

  7. #6
    Thx sangoma, that works out great. But I'll try to learn about expect in any case.

Posting Permissions

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