473,395 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Query in NET:Telnet module

Hello all
i am using net:telnet module to login to the remote machine and execute some commands and to collect some logs corresponding to the command given.
After loging into the machine I do patternmatch for a string and collect the logs and store it in a file.
The code for the same is given below.

Expand|Select|Wrap|Line Numbers
  1. $telnet->print('cmd1');#command to be executed
  2. sleep(5);
  3. ($prematch,$match) = $telnet->waitfor(
  4.     String  => "2>",
  5.     Timeout => 10 ,
  6.     Errmode => 'return',
  7. );
  8. open(OUTFILE1,">x");
  9. print OUTFILE1 ($prematch);#copying the logs of cmd into a file.
  10. close(OUTFILE1);
  11.  
The above code works fine and iam able to see the contents in the file "X" created.

I need to modify the code in such a way that all the logs must be stored in the file even if I cont match any pattern(bcoz logs will be varying
I will not be able match any pattern)I just tried giving String => "" but it doesnot work and the content of the file "x"is zero.

I did some search in google and the info i got is

The waitfor() method is the workhorse of Net::Telnet. It waits up to Timeout seconds for the specified string or pattern to appear on the data stream coming from the remote host. In a scalar context, waitfor() returns a true value if the desired pattern was seen.

The issue here is I cont match any pattern in that case how can I get the logs from remote host.

Any pointers in solving it will be helpful.
Sep 5 '07 #1
2 4834
KevinADC
4,059 Expert 2GB
It sounds like you want to read all the lines of the files:

getlines - read next lines

@lines = $obj->getlines([Binmode => $mode,]
[Errmode => $errmode,]
[Input_record_separator => $chars,]
[Rs => $chars,]
[Telnetmode => $mode,]
[Timeout => $secs,]
[All => $boolean,]);

This method reads and returns all the lines of data from the object until end of file is read. You can use input_record_separator() to change the notion of what separates a line. The default is "\n". A time-out error occurs if all the lines can't be read within the time-out interval. See timeout().
Sep 5 '07 #2
Thanks kevin I tried the same and it worked.

This is the code i have

Expand|Select|Wrap|Line Numbers
  1. $telnet3->print("monitor log");
  2. sleep(40);
  3. @lines = $telnet3->getlines(
  4.     Binmode    => 0,
  5.     # Errmode    => $errmode,
  6.     Input_record_separator => $chars,
  7.     Rs         => $chars,
  8.     Telnetmode => $mode,
  9.     Timeout    => $secs,
  10.     All        => $boolean,
  11. );
  12. print @lines;
  13.  
  14. $telnet3->print('quit');
  15.  
when I did this Iam able to see all the logs.If you see i have a given a sleep time of 40 secons so iam able to see all the logs only upto 40 sec.(If i dont give sleep time iam not able to see any logs)
I cont hardcode this value as we cont predict the time.
Iam not sure if we can acheive this by the folling process.
i want to run run this script without this line($telnet3->print('quit');) so it never quits from the host and keep it in a infiniteloop(by including a while loop) and run another perl script which inturn kill this perl script and collect the logs.
is there anyother betterway to do this.
Sep 6 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Pete Johansen | last post by:
Hi Folks, This prompt statement has been a real pain in the the butt. I am using net::telnet(v3.03) to connect to a W2K box from a Solaris 2.6 box. I the output stream resulting from a 'dir'...
2
by: Vinay Gupta | last post by:
Hi, In a Perl to Tcl conversion project, I am planning to use the following Tcl extensions as a replacement for some Perl libraries. My development environment is Windows. Win32::OLE --> "DDE"...
1
by: kriz4321 | last post by:
Hi all, This is the code I use to login to any device.( I will not be able to see any window but it will be able to login to the device and give the command specified)... can you tell me what...
1
by: jyohere | last post by:
I want to login to a remote machine using Net::Telnet....then i want to move to a particular directory in that remote machine....after that i want to get a list of files under that directory....after...
0
by: shineyang | last post by:
Dear all: Who is kind to help me about the following problem. Why cannot log the remote node by using Net::Telent #################################### The following is normal to the process...
3
by: surajsingh | last post by:
Hi, I have a perl script which uses Net::Telnet module to open a telnet session with my unix boxes, and executes lot of commands on those boxes. As this module is implemented, when 'cmd' is...
2
by: jane007 | last post by:
Hi everybody, Anybody who know how to use Net::Telnet module to execute my own script?Not only to execute system command. Please advise. Thanks.
21
by: poolboi | last post by:
hi guys, a question on net::telnet what does this module do? cos i have a telnet client that will be able to communicate with a database so is it true if i enter my ip address, username, and...
0
by: SteveBark | last post by:
Any pointers on this truly appreciated. I am using net::telnet to connect to a modem pool and then connect with a remote piece of kit. Everything works fine normally, however on occassions the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.