Shell Script Commands to Automate Server or Host Telnet Login Session

In linux,we usually come across repeated commands which we try to automate usinng shell scripts.One such major need arises,when we need to establish a telnet session to a system and perform some repeated commands in remote server or host.
So,In order to automate the telnet sessions,you just need to copy the following code in a file (say,node_login) and place it in the home directory.

#! /usr/bin/env expect
set ip [lindex $argv 0 ]
set slot [lindex $argv 1]
set timeout -1
set node_ip $ip
if {[llength $argv] == 1} {
spawn telnet 192.168.15.$node_ip
expect "login: "
send "root\r"
expect "Password: "
send "techtips\r"
expect "$"
}
if {[llength $argv] == 2} {
spawn telnet 192.168.15.$node_ip $slot
expect "login: "
send "root\r"
expect "Password: "
send "techtips\r"
}
if {[llength $argv] == 0} {
spawn telnet 192.168.90.103
expect "login: "
send "techtips\r"
expect "Password: "
send "techtips\r"
expect "$ "
}
interact

Now add the command to your .bashrc file in your home directory.
alias node='/home/tectips/node_login'

Here,you must specify your path to your file earlier saved.So,when you type the keyword ‘node’,it will automatically login to your node with login and password you have provided in your scripts.

I have given three conditions,

i.If you type ‘node’ in your console,

command executed:   telnet 192.168.90.103

2.if you type ‘node 114′ (you have given the last substring of your ip)

command executed:   telent 192.168.90.114

3.If you type ‘node 114 1098′ (you have given last substring of your ip as well as your port)

command executed:  telnet 192.168.90.114 1098

You can change the subnet of the network as you wish by editing the scripts ,add commands after establishing telnet sessions,and enjoy automation.

3 Responses to “Shell Script Commands to Automate Server or Host Telnet Login Session”

  1. Can you please explain the lines in the script? Like how and why have you used it?

  2. this is a auotmated script to login to any machine(telnet sessions),with your username and passord.

  3. thanks,buddy,hope u get in 100,000 in alexa,good luck!

Leave a Reply