Operating System - HP-UX
1820614 Members
1876 Online
109626 Solutions
New Discussion юеВ

Re: Automating telnet script

 
SOLVED
Go to solution
Tim O'Connell
Regular Advisor

Automating telnet script

Hi,

I'm on HPUX 11.11i. Does anyone know if it is possible to automate a telnet script & pass in the username, password & a command and the exit. For testing purposes, I need to write a script to telnet to a router & run the command "sh dialer". I can't seem to find a way to pass the details to telnet from a file.
what I need to do in words is:
telnet 11.11.111.111 (i.e. IP address)
input USERNAME
input PASSWORD
sh dialer
exit

This will be run in the crontab overnight & thescreen output send to a log file for monitoring

Thanks,

Tim
8 REPLIES 8
Mobeen_1
Esteemed Contributor

Re: Automating telnet script

Tim,
I think the following should work, i don't have access to a Unix system right now to verify

$ telnet 11.11.111.111
USERNAME
PASSWORD
sh dialer
exit

OR

$ telnet 11.11.111.111 USERNAME PASSWORD
sh dialer
exit

Try and let me know if one of the above works

rgds
Mobeen
Peter Godron
Honored Contributor
Solution

Re: Automating telnet script

Tim,
the normal way for doing this in a production environment would be via expect.
See
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=45609
for solution of your problem.
Regards
Tim O'Connell
Regular Advisor

Re: Automating telnet script

Sorry, Mobeen

The telnet commands did'nt work

Will look at Expect.

Points assigned

Thanks,

Tim
Matthew_50
Valued Contributor

Re: Automating telnet script

expect script sample

#!/usr/local/bin/expect -f
spawn telnet 123.123.123.123
expect "login:"
send "snoopy\r"
expect "Password:"
send "snoopy\r"

Chris Vail
Honored Contributor

Re: Automating telnet script

This is a BAD idea: don't do it! It reflects poor system security practice. Telnet sends passwords unencrypted. If telnet is the only connection offered by the router, your system is badly out of date.

Try echo "$USERNAME\r$PASSWORD\r$COMMAND"|telnet HOST.
(The \r is the equivalent of the key. If this doesn't work, try \013 instead of the \r. The \013 is the octal equivalent of the key.)

This is really ugly, but might work for you. I can't test this on any of my systems here or the security people would have my head on a platter--and rightfully so.
Chris Vail
Honored Contributor

Re: Automating telnet script

Oops: I told you wrong. The octal equivalent of \r is \015, not \013. Sometimes I confuse myself.


Chris
Biswajit Tripathy
Honored Contributor

Re: Automating telnet script

AFAIK, "echo usrname\rpasswd | telnet HOST" does
not work for telnet as telnet, by default, reads from
tty.

- Biswajit
:-)
Tim O'Connell
Regular Advisor

Re: Automating telnet script

Thanks for all the replies. I know telnet has its holes but I won't be running this for long. I am trying to determine which pc's are bringing up the ISDN lines at night. I got it working by doing the following: (PASSWORD is the password on the router)

router=99.99.999.99
(echo PASSWORD
sleep 2
echo sh isdn act
sleep 2
echo exit
while read cmd
do
echo $cmd
done
)|telnet $router | tee /tmp/ky_routers_up.log

Points awarded,

Thanks

Tim