473,591 Members | 2,810 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Query in NET:Telnet module

48 New Member
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 4848
KevinADC
4,059 Recognized Expert Specialist
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_se parator => $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_se parator() 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
kriz4321
48 New Member
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
4116
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' command I am getting control characters and a line-feed. Here is an example from the input_log: .. .. ..
2
6082
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" or "OpTcl" LWP::UserAgent, HTTP::Request --> "Scotty" Net::Telnet --> "Expect" ('spawn telnet') I have used Expect but haven't used Scotty, DDE or OpTcl before.
1
1623
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 changes I should do so that I can see what happens ...(like telnetting to the device ) Hope you can get my question $telnet3 = new Net::Telnet( Timeout => 10, Errmode => 'die', ); $telnet3->open('192.168.134.36'); # Substituted...
1
1688
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 that i want to ftp those using Net::Ftp to my machine itself....i am a java programmer....but i wanted to write a script for the above said.....i dont know perl also.,....pls help....plssssss
0
1487
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 using "Telnet" #################################### $ telnet 172.30.9.2 Trying 172.30.9.2...
3
2042
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 used, this module waits for the 'prompt' to decide whether the command is finished or not. Now in case the 'timeout' is reached before the 'prompt' appears, the module directly throws error (even if the command might actually be running on the remote...
2
5725
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
2788
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 password and using print later again to execute some commands i will get some results on some screen??
0
3493
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 remote piece of kit may be busy and will not talk to me, leaving me to logoff cleanly and try again later. Using net::telnet and the following code I am trying to wait for the prompt of ? to be returned if it is not returned after 60 seconds I wisk...
0
7870
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8236
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8362
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7992
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
5732
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5400
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3850
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3891
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2378
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.