Script_to_Login_Cisco_Router_without_using_Expect


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script_to_Login_Cisco_Router_without_using_Expect
# 1  
Old 09-24-2012
Error 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
# 2  
Old 09-24-2012
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?
# 3  
Old 09-24-2012
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
# 4  
Old 09-24-2012
You could try something like this (not sure if it will work on port 23):

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

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

EOF

This User Gave Thanks to toro95037 For This Post:
# 5  
Old 09-24-2012
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.
# 6  
Old 09-25-2012
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..
# 7  
Old 09-27-2012
(ssh is the best way to go) ...but,

I did get this working with no expect commands on port 23:
(vi telnetpass.sh)
Code:
#!/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:
Code:
. 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):>

This User Gave Thanks to toro95037 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread
Login or Register to Ask a Question