Modify a batch file that could open a Telnet Session

Asked By 10 points N/A Posted on -

I wrote a batch file that could open a Telnet Session. How do I modify  the batch file to automatically  set my  login user name and password  so that I don’t have to type my username and passwords every time I want to login into the session?

Answered By 0 points N/A #100028

Modify a batch file that could open a Telnet Session


Dear Paulthomas8215,

It would have been better if you had provided your script also.

However, in order to start the telnet session without providing your username and password every time,

Locate and download program called “ EXPECT” from Expect is a tool for automating the interactive applications like telnet. After downloading this program, Then, on the unix system at the command line, type:

gunzip expect.tar.gz

tar -xvf expect.tar

A directory will be created directory containing the Expect distribution. Change to that directory and read the README file, which contains all the installation instructions.

Now download another application called “Tcl” which can be downloaded from here. However as far as we know that cl and Tk come preinstalled on most Unix systems, but do check the version whether it the latest or not, to do so : run “tclsh” from command line and type “infopatchlevel”.

After both the EXPECT and TCL are present on unix, you can now write as below:

#!/usr/local/bin/expect (this is the directory where expect is installed).

spawn telnet <machine ip>

expect "login:"

send "<username>n"

expect "Password:"

send "<password>n"

send "bashn"

send "cd /optn"

send "ls -ltrn"

Now to execute the “expect“ command expect –f <file name>

Ex: expect –f <filename>.expect



Login/Register to Answer

Related Questions