April 19, 2014


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.

Comments

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

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

  3. Excellent.

    To automate sessions with FTP servers (instead of telnet), I discovered this script.

    http://www.biterscripting.com/helppages/SS_FTPUpload.html

    And, to automate sessions with web/HTTP servers (instead of FTP), i figured out a script in biterscripting like this. Wanted to share them with you because they save immense amount of manual typing and clicking.

    # Session start
    isstart “email” “daily email check” “Mozilla/4.0″
    # Connect to email server
    isconnect “email” “http://www.some_server.com”
    # Exchange cookies
    script “SS_ISCookies.txt” from(“email”) to(“email”)
    # Login
    issubmit “email” “/emailform.xxx” “login=xxx” “password=yyy”

    # .
    # .
    # .

    # Session end
    isdisconnect “email”
    isend “email”

    The script is in biterscripting. Makes it very easy.

  4. hi,

    need to login to four different hosts through ssh and run a script which gives me the output can you please help.it prompts for a password when i login to each host

  5. awesome to be here.

Speak Your Mind

*