Operating System - HP-UX
1819910 Members
2511 Online
109607 Solutions
New Discussion юеВ

Re: How to make Telnet Perl Script

 
jon_90
New Member

How to make Telnet Perl Script

Hi,

I need a perl script that will telnet to a router/switch specified by hpov alert. Then it will issue `show proc cpu` and save the result in a text file.

Help will be greatly aprreciated.

Thanks,
jonathan
12 REPLIES 12

Re: How to make Telnet Perl Script

hi jon,

you can use the Net::Telnet::Cisco package for this purpose. access this site http://nettelnetcisco.sourceforge.net/docs.html to find any reference for Cisco router. attached below is a sample perl script. You can modify this to your needs.

thanks,
Rodel
Balaji N
Honored Contributor

Re: How to make Telnet Perl Script

hi
not sure of perl script. but an easy solution is to use expect.

expect is used to automate interactive commands.

check out the below link for more details.

http://hpux.connect.org.uk/hppd/hpux/Tcl/expect-5.38/

cheers
-balaji
Its Always Important To Know, What People Think Of You. Then, Of Course, You Surprise Them By Giving More.
Jonathan_63
New Member

Re: How to make Telnet Perl Script

Hi Rodel,

Thanks for the script. I have it running already.

Now i want to attach the result file to a sendmail. How would i do it? i have a script using sendmail working, just need the code for attaching a file.

thanks.
jonathan
Yogeeraj_1
Honored Contributor

Re: How to make Telnet Perl Script

hi,

One simple way, will be to include the file into the body itself.
========================================================
dt=`date +%y%m%d-%H%M`
errorlogfile="$LOGPATH/mylog$dt.log"
emailadd1="yd@myworld.mu"
subject="My logfile"

/usr/bin/mailx -s "$subject" $emailadd1 < $errorlogfile
========================================================

If you want it as an attachement, try:
/usr/bin/uuencode $errorlogfile "TheLogfile.log"|mailx -m -s "This is the file you need [subject] on `date`" $emailadd1

Hope this helps!
Yogeeraj
No person was ever honoured for what he received. Honour has been the reward for what he gave (clavin coolidge)
Ralph Grothe
Honored Contributor

Re: How to make Telnet Perl Script

Jonathan,

the easiest way to make a mail attachment is to use the MIME::Lite module from CPAN.

Have a look here for a short sample, or better consult your already installed POD on your system

http://www.perldoc.com/perl5.8.0/pod/perlfaq9.html#How-do-I-use-MIME-to-make-an-attachment-to-a-mail-message-
Madness, thy name is system administration
Jonathan_63
New Member

Re: How to make Telnet Perl Script

Hi Ralph,

Will the Mime::Lite replace this code for sending mail?

# Send Mail
$sendmail = "/usr/lib/sendmail -t";
$to = "To: abc@123.com\n";
$from = "From: 123@abc.com\n";
#$reply_to = "Reply-To: 123@abc.com\n";
$subject = "Subject: Mail\n";
$content = "\n";

open(SENDMAIL, "|$sendmail") or die "Cannot opem $sendmail: $!";
print SENDMAIL $to;
print SENDMAIL $from;
#print SENDMAIL $reply_to;
print SENDMAIL $subject;
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL $content;
close(SENDMAIL);
John Meissner
Esteemed Contributor

Re: How to make Telnet Perl Script

I don't know that much perl but I would use expect.

i'm attaching an example script
All paths lead to destiny
Ralph Grothe
Honored Contributor

Re: How to make Telnet Perl Script

Not necessarily completely since you may combine your more "low level" invocation of your MTA with the module methods.

But (as always with Perl) you have several options since a module like MIME::Lite or the MIME::Tools put an extra abstraction layer over the mail transfer, where you may specify your MTA or let the module take what it detcts as default (this makes your Perl code a bit OS and MTA independent, provided you've got the right set of modules installed).

I'd suggest to get the MIME::Tools from CPAN

http://www.perl.com/CPAN/authors/Eryq/

In it's README you will find that they depend on a couple of other modules because they inherit from them which you also may have to install.

As an attachment I uploaded the output from the POD of MIME::Tools that comes with exactly one example in its synopsis that suits your piping to sendmail way.
Madness, thy name is system administration

Re: How to make Telnet Perl Script

hi jon,

how about assigning us some points? I believe I have answered your main query for making a Telnet PERL script.

regards.

Rodel
Jonathan_63
New Member

Re: How to make Telnet Perl Script

Of course! Can you show me how? Sorry.

Re: How to make Telnet Perl Script

hi jon,

just click on the "how to earn points" link and you will find there the procedure to assign points.

thanks.
Rodney Hills
Honored Contributor

Re: How to make Telnet Perl Script

To assign points, be sure you connect on with your original sign on of "jon". Your replies to this thread are from a different user.

-- Rod Hills
There be dragons...