- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Automating a Telnet Session
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2001 07:28 AM
10-02-2001 07:28 AM
Automating a Telnet Session
Here's an excerpt of what I'm having problems with:
(echo "password";echo "show ip nat trans";sleep 30) | telnet $IP_ADDRESS > $DIR/info.$TAG
Basically I thought this would echo the router password (yeah I know it's clear text) and router command piping them through telnet and redirect the output to a file.
What happens though is that I seem to get to the router (it responds with the expected prompt, but it's as if I'm not really logged in. I cannot issue any commands to it.
Even if I just try on the command line to pipe the password to the telnet session it appears to log in but I cannot type any commands.
Is there something I'm doing wrong in trying to initiate this telnet session?
I thought about Expect but was hoping to avoid the addition of another piece of software. Are there other ways to automate telnet sessions?
Thanks much,
-mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2001 07:53 AM
10-02-2001 07:53 AM
Re: Automating a Telnet Session
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2001 08:09 AM
10-02-2001 08:09 AM
Re: Automating a Telnet Session
Try 'remsh' or 'rexec', as for instance:
# remsh thehost -l root -n "(date;hostname;pwd) > /tmp/result"
...which would place the output of the commands into /tmp/result on 'thehost', and then:
# remsh thehost -l root -n "cat /tmp/result"
Regards!
...JRF...
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2001 08:11 AM
10-02-2001 08:11 AM
Re: Automating a Telnet Session
I think it's better to use expect, but you can
try with telnet. Don't forget to add a sleep
between each stage of connection :
#!/bin/sh
# Wait login prompt
sleep 5
echo $LOGIN
# Wait passwd prompt
sleep 5
echo $PASSWD
# Wait connection is established
echo ls
# Here your commands are executed (don't use sleep)
# Don't forget to disconnect from remote
echo exit
# At the end don't forget to quit your script
# after executions
sleep 30
exit
You need to try to find your own sleeping times.
HTH
Herv?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2001 08:26 AM
10-02-2001 08:26 AM
Re: Automating a Telnet Session
As pointed by Herves, sleep is very important.
Try like this
(sleep 5
echo password
sleep 5
echo show ip nat trans
sleep 15
echo exit) |telnet $IP_Address
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2001 10:20 AM
10-02-2001 10:20 AM
Re: Automating a Telnet Session
I guess I am going to have to install Expect. Can I get this through the HP-UX Shareware site? Are any of you using it? I'd like to get any feedback about it you could share.
Thanks again,
-mark
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2001 11:40 AM
10-02-2001 11:40 AM
Re: Automating a Telnet Session
You can get expect from this following site free.
http://hpux.ee.ualberta.ca/hppd/hpux/Tcl/expect-5.31/
You can use this sample script to get what you want.
#!/wherever/expect -f
set prompt "(%|#|\\$|>)"
set timeout 10
spawn telnet $IP_ADDRESS
expect "login: "
send "password\r"
expect "$prompt"
send "show ip nat trans "
expect "$prompt"
send "exit\r"
You can simplify the script by replacing $prompt with the prompt of your router.
The above is only a template. May not work.
-Sri
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-02-2001 12:22 PM
10-02-2001 12:22 PM
Re: Automating a Telnet Session
http://hpux.ee.ualberta.ca/hppd/hpux/Tcl/tcl-8.2.1/
http://hpux.ee.ualberta.ca/hppd/hpux/Tcl/tk-8.2.1/
install these and then the expect depot and you'll be all set to write a script. You should be able to find some examples at
http://www.scriptics.com/scripting/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2001 04:26 AM
10-03-2001 04:26 AM
Re: Automating a Telnet Session
If I understand correctly, you want to do the Batch Telnet I mean u want to execute some script or commands on other systems thru telnet.
If you want to execute the just the script on the other system then the best way to make the Trust Relationship between the two systems and then use the remsh command.
If you don't want to go with this and simply want Batch Telnet then follow the steps:
1. You should have Perl 5.6.1 or later version install on your machine; not necessary on the other end.
2. Just copy this under the $PERL_HOME/site/lib/Net directory(Attached)
you can find more about this at http://search.cpan.org/doc/JROGERS/Net-Telnet-3.02/lib/Net/Telnet.pm
3. Write this simple perl script
use Net::Telnet ();
$t = new Net::Telnet (Timeout => 90,
Errmode=>'die');
$t->open('your hostname');
$t->waitfor('/login: $/i');
$t->print('your_username');
$t->waitfor('/password: $/i');
$t->print('your_password');
$t->waitfor('/\$ $/i');
$t->print('script_to_run');
@lines = $t->waitfor('/\$ $/i');
print @lines;
Now just replace the above with your info.
your_hostname
your_username
your_password
script_to_run
This will solve your problem.
Thanks
Zafar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-24-2001 05:54 PM
10-24-2001 05:54 PM
Re: Automating a Telnet Session
The script below shows how to send some initial commands to a router (like password) and then enter your own commands.
router=
( echo
echo
echo
while read cmd
echo $cmd
done
) | telnet $router | tee
You may want to sleep for a few seconds between commands but I have not needed to.
Of course to have no input from you required, echo exit inside the brackets and remove the while loop. The output can then be redirected to a file rather than tee'd.
From my understanding, the reason your original script didn't work is that you were typing in was not being picked up by the script and passed on to the telnet session.
It does not work trying to script a session to another unix host. Any ideas on why?
Sean