N/APosted on - 11/01/2011
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?
Modify a batch file that could open a Telnet Session
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 https://sourceforge.net/projects/expect/. 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:
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>
send "cd /optn"
send "ls -ltrn"
Now to execute the “expect“ command expect –f <file name>
Ex: expect –f <filename>.expect