- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: How to write script for telnet session
Operating System - HP-UX
1754020
Members
7209
Online
108811
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Topic Options
- 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
07-01-2004 01:29 AM
07-01-2004 01:29 AM
Re: How to write script for telnet session
I've written some telnet scripts in PERL.
PERL has a telnet module. With it, I can login to my routers, enter commands to the routers to gather statistics. The script looks like this
#!/usr/contrib/bin/perl -w -I/opt/perl/lib/5.6.1/Net
#
use Telnet;
$|=1;
$Vanguard=shift(@ARGV);
$Password=shift(@ARGV);
$theVanguard=Net::Telnet->new(Timeout=>10,Prompt=>'/OK\n/',Host=>$Vanguard)
or die("Cannot Connect $Vanguard");
print "Hostname : $Vanguard\n";
#################
# Wait for OK - then send ATDS to connect
#################
$theVanguard->prompt("/Enter Password:/");
@listing=$theVanguard->cmd("atds");
print "@listing";
###
# Enter password and wait for enter selection prompt
###
$theVanguard->prompt('/Enter Selection:/');
@listing=$theVanguard->cmd($Password) or die ("Wrong Password $Vanguard\n");
print "@listing";
###
# Enter Commands to get statistics
###
$theVanguard->prompt('/Enter Selection:/');
@listing=$theVanguard->cmd("5");
print "@listing";
The $theVanguard=Net::Telnet->new(Timeout=>10,Prompt=>'/OK\n/',Host=>$Vanguard)
opens the connection to the host($Vanguard which is the first argument passed to the script) and waits for the host to respond with "OK" for up to 10 seconds. If it fails then the die clause is executed.
It sends the password to the host (which is the second argument passed to the script) and waits for up to 10 seconds for the host to respond with "Enter Selection"
When the enter selection is sent, it starts sending commands to the host. The @listing array contains the host's responses to the commands that are printed to stdout. I generally redirect standard out to a file for later review.
PERL Black Book ISBN: 1-57610-465-6 Publiched by CoriolisOpen Press Written by Steven Holzer is an excellent resource and contains the documentation on using the telnet module.
-Good Luck
PERL has a telnet module. With it, I can login to my routers, enter commands to the routers to gather statistics. The script looks like this
#!/usr/contrib/bin/perl -w -I/opt/perl/lib/5.6.1/Net
#
use Telnet;
$|=1;
$Vanguard=shift(@ARGV);
$Password=shift(@ARGV);
$theVanguard=Net::Telnet->new(Timeout=>10,Prompt=>'/OK\n/',Host=>$Vanguard)
or die("Cannot Connect $Vanguard");
print "Hostname : $Vanguard\n";
#################
# Wait for OK - then send ATDS to connect
#################
$theVanguard->prompt("/Enter Password:/");
@listing=$theVanguard->cmd("atds");
print "@listing";
###
# Enter password and wait for enter selection prompt
###
$theVanguard->prompt('/Enter Selection:/');
@listing=$theVanguard->cmd($Password) or die ("Wrong Password $Vanguard\n");
print "@listing";
###
# Enter Commands to get statistics
###
$theVanguard->prompt('/Enter Selection:/');
@listing=$theVanguard->cmd("5");
print "@listing";
The $theVanguard=Net::Telnet->new(Timeout=>10,Prompt=>'/OK\n/',Host=>$Vanguard)
opens the connection to the host($Vanguard which is the first argument passed to the script) and waits for the host to respond with "OK" for up to 10 seconds. If it fails then the die clause is executed.
It sends the password to the host (which is the second argument passed to the script) and waits for up to 10 seconds for the host to respond with "Enter Selection"
When the enter selection is sent, it starts sending commands to the host. The @listing array contains the host's responses to the commands that are printed to stdout. I generally redirect standard out to a file for later review.
PERL Black Book ISBN: 1-57610-465-6 Publiched by CoriolisOpen Press Written by Steven Holzer is an excellent resource and contains the documentation on using the telnet module.
-Good Luck
"Only he who attempts the absurd is capable of achieving the impossible
- Tags:
- telnet
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-01-2004 02:13 AM
07-01-2004 02:13 AM
Re: How to write script for telnet session
I've used both Expect, Perl and KSH and found expect 100 times less cryptic to write these type of things then Perl..
We are using it for in house OLTP between multiple boxes, inserting records into Informix, Postgres or Mysql databases..
In addition to automated file transfers..
I general use perl for in file edits, using perl -pi -e g///s file and that's about it.
We are using it for in house OLTP between multiple boxes, inserting records into Informix, Postgres or Mysql databases..
In addition to automated file transfers..
I general use perl for in file edits, using perl -pi -e g/
- « Previous
-
- 1
- 2
- Next »
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP