Script_to_Login_Cisco_Router_without_using_Expect

Hi All,

Am bit new to Shell scripting, I've used some scripts using expect shell to logon to a router, But in my current organization i don't have the package is get installed and do not have the permission to do install also.

Can anyone please suggest me a way how to write a script to log-on into a cisco router without using "expect" in shell script.

Thanks in advance,
Jeeva Ganesan

you seem to have a bit of knowledge on what you are trying to accomplish and how to do it, how about passwordless ssh login?

I need to do a script using telnet by passing the host IP address as command line input with hard coded credentials in script as we have different set of routers with same credentials

You could try something like this (not sure if it will work on port 23):

username="myLogin"
password=`cat passwd.txt`

telnet 192.168.10.100 8101 <<EOF       
    $username
    $password
    #insert command here

EOF

1 Like

If it absolutely has to be telnet, hard to script this without expect.

But as others say, you should be looking into the ssh option. That could be done elegantly.

Hi Corona,
What need to be done if Ok to go with SSH..

---------- Post updated at 12:36 AM ---------- Previous update was at 12:35 AM ----------

Hi Toro,
I tried with this, But its not works on port 23..

(ssh is the best way to go) ...but,

I did get this working with no expect commands on port 23:
(vi telnetpass.sh)

#!/bin/sh
host=test001.your.company.com
port=23
login=admin
passwd=adminpass
cmd="date;hostname;hostname -i"

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

the way to execute is:

. telnetpass.sh | telnet

(1031):> . telnetpass.sh | telnet
telnet> Trying 192.168.100.10...
Connected to test001.your.company.com (192.168.100.10).
Escape character is '^]'.
Red Hat Enterprise Linux Server release 5.5 (Tikanga)
Kernel 2.6.18-194.el5 on an x86_64
login: admin
Password:
Last login: Sun Sep 23 10:57:56 from test008.your.company.com

+-------------   test001.your.company.com  -------------+

:: Red Hat Enterprise Linux Server release 5.5 (Tikanga)
:: 2.6.18-194.el5
:: 192.168.100.10
:: Image deployment date
:: 2011-Nov-22 ... 15:58:33

date;hostname;hostname -i
[admin@hdtest001 ~]$ date;hostname;hostname -i
Thu Sep 27 13:55:01 PDT 2012
test001.your.company.com
192.168.100.10
[admin@test001 ~]$ Connection closed by foreign host.

(1032):> 

1 Like

HI Toro,

My many days search fulfilled :slight_smile: In this the connection to the host getting closed if i want the connection to be make active means what i need add on this.

Re post #8.
This implies that you are staying connected on a telnet session until you get timed out.

What are you actually trying to do? If you are trying to monitor Cisco routers real-time, then there are much better tools on the market.

I want to create a auto login script by getting host ip address as command line input, once it is logged in Will execute some commands and will do some configuration and will close the session manually.

Problem is in all of our current machine am not able to use "expect" shell for scripting